usaco 6.1 Postal Vans(插头DP)

Postal Vans

ACM South Pacific Region -- 2003

Tiring of their idyllic fields, the cows have moved to a new suburb. The suburb is a rectangular grid of streets with a post office at its Northwest corner. It has four avenues running East-West and N (1 <= N <= 1000) streets running North-South.

For example, the following diagram shows such a suburb with N=5 streets, with the avenues depicted as horizontal lines, and the post office as a dark blob at the top-left corner:

Each day the postal van leaves the post office, drives around the suburb and returns to the post office, passing exactly once through every intersection (including those on borders or corners). The executives from the post company want to know how many distinct routes can be established for the postal van (of course, the route direction is significant in this count).

For example, the following diagrams show two such routes for the above suburb:

As another example, the following diagrams show all the four possible routes for a suburb with N=3 streets:

Write a program that will determine the number of such distinct routes given the number of streets.

PROGRAM NAME: vans

INPUT FORMAT

  • Line 1: A single integer, N

SAMPLE INPUT (file vans.in)

4

OUTPUT FORMAT

  • Line 1: A single integer that tells how many possible distinct routes corresponding to the number of streets given in the input.

SAMPLE OUTPUT (file vans.out)

12
题意:求4行n列的一条回路问题,回路分方向。。。
分析:一条回路问题,而且只要4行,直接暴力枚举两列之间所有状态转移,然后写个大数就搞定了
PS:好久没写大数,wa了一大堆啊T_T
代码:
/*
ID: 15114582
PROG: vans
LANG: C++
*/
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
struct BigNum
{
    int s[111],w;
    BigNum()
    {
        w=1;
        memset(s,0,sizeof(s));
    }
    void add(BigNum a)
    {
        if(a.w>w)w=a.w;
        for(int i=0;i<w;++i)
        {
            s[i]+=a.s[i];
            s[i+1]+=s[i]/100000;
            s[i]%=100000;
        }
        while(s[w])++w;
    }
    void out()
    {
        printf("%d",s[w-1]);
        for(int i=w-2;i>=0;--i)
            printf("%05d",s[i]);
        puts("");
    }
}f[1111][6],ans;
int i,j,n;
int main()
{
    freopen("vans.in","r",stdin);
    freopen("vans.out","w",stdout);
    f[1][0].s[0]=f[1][1].s[0]=1;
    for(i=2;i<1001;++i)
    {
        f[i][0].add(f[i-1][0]);
        f[i][0].add(f[i-1][2]);
        f[i][0].add(f[i-1][4]);
        f[i][1]=f[i][0];
        f[i][1].add(f[i-1][3]);
        f[i][2].add(f[i-1][1]);
        f[i][2].add(f[i-1][5]);
        f[i][3]=f[i-1][1];
        f[i][4]=f[i][2];
        f[i][5]=f[i][2];
    }
    while(~scanf("%d",&n))
    {
        ans=f[n-1][1];
        ans.add(f[n-1][5]);
        ans.add(ans);
        ans.out();
    }
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值