hdu1246自共轭Ferrers图

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1246


参照大神的DP的思路:

状态方程:f[i][j] = f[i][j - 1] + f[i - 2 * j + 1][j - 1] ,f[i][j]代表了i个方格第一行不超过j 解得的个数。


代码:


#include <cstdio>

int f[500][500];
const int maxn = 300;
void init()

{
    for(int i = 0;i <= maxn;++i)
        f[0][i] = 1;

    for(int i = 1;i <= maxn;++i)
    {
        for(int j = 1;j <= maxn;++j)
        {
            f[i][j] = f[i][j - 1];
            if(2 * j - 1 <= i)
                f[i][j] += f[i - 2 * j + 1][j - 1];
        }
    }
}
int main()

{
    init();
    int n;
    while(~scanf("%d",&n))
    {
        printf("%d\n",f[n][n]);
    }
    return 0;
}

你可能感兴趣的:(dp,ACM,递推)