[HDU] 4472 Count 排列组合型Dp

 

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

方法:该题目不是最优解类型的dp,属于排列组合的dp,根据题目建好模型后得到如下状态转移方程:

    {

    1, n==1;

F(n) =

    Sum{F((n-1)/x)| (n-1)%x == 0 && 1<=x<=n-1}, n>=2;

    }

最终F(N)为解。

感谢:简单题。

代码:

View Code
#include<iostream>
#include<math.h>
//#include<algorithm>
//#include<queue>
//#include<stack>
using namespace std;
int const MAX =0x3f3f3f3f;
 
int result[1001];
int mod = 1000000000+7;
int main()
{
    int n = 0;
    memset(result,-1,sizeof(result));
    result[1]=result[2]=1;
    int i =1;
    while(scanf("%d",&n)!=EOF)
    {
        cout<<"Case "<<i<<": ";
        if(result[n]==-1)
        {
            for(int x=3;x<=n;x++)
            {
                int sum = 0;
                for(int y=1;y<=x-1;y++)
                {
                    if( (x-1)%y==0 )
                    {
                        sum+= (result[(x-1)/y])%mod;
                    }
                }
                result[x]=sum%mod;
            }
        }
        cout<<result[n]<<endl;
        i++;
    }
    return 0;
} 

 

 

posted @ 2013-04-23 15:55  kbyd  阅读(142)  评论(0编辑  收藏  举报