码迷,mamicode.com
首页 > 其他好文 > 详细

[USACO 6.1.1]Postal Vans

时间:2016-07-06 14:43:30      阅读:275      评论:0      收藏:0      [点我收藏+]

标签:

题目大意

  给一个4*n的矩阵,矩阵看成无向图,求哈密顿回路方案数.

题解

  看了题解才懂.不然身为蒟蒻的我怎么可能推出递推式23333

  附网址http://blog.csdn.net/jiangshibiao/article/details/21446033

  代码和上面的有所不同.

代码

/*
TASK:vans
LANG:C++
*/
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

struct Bigint
{
    static const int BASE = 10000;
    int s[200], len;
    
    Bigint()
    {
        memset(s, 0, sizeof(s));
        len = 1;
    }
    
    Bigint operator + (const Bigint &b)
    {
        Bigint c;
        c.len = max(len, b.len);
        for (int i = 0; i < c.len; ++i)
        {
            c.s[i] += s[i] + b.s[i];
            c.s[i + 1] = c.s[i] / BASE;
            c.s[i] %= BASE;
        }
        if (c.s[c.len]) c.len++;
        return c;
    }
};

int n;
Bigint f[1005], g[1005], s[1005];

int main()
{
    freopen("vans.in", "r", stdin);
    freopen("vans.out", "w", stdout);
    scanf("%d", &n);
    f[1].s[0] = 0;
    f[2].s[0] = 2;
    g[1].s[0] = 2;
    s[1].s[0] = 0;
    g[2].s[0] = 2;
    s[2].s[0] = 2;
    for (int i = 3; i <= n; ++i)
    {
        f[i] = f[i - 1] + g[i - 1];
        s[i] = f[i - 2] + f[i - 2] + s[i - 1];
        g[i] = f[i - 1] + f[i - 1] + g[i - 2] + s[i];
    }
    printf("%d", f[n].s[f[n].len - 1]);
    for (int i = f[n].len - 2; i >= 0; --i) printf("%04d", f[n].s[i]);
    printf("\n");
    return 0;
}

 

[USACO 6.1.1]Postal Vans

标签:

原文地址:http://www.cnblogs.com/albert7xie/p/5646571.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!