首页 > 代码库 > hdu1267(递推)

hdu1267(递推)

 

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

题意:
假定一个字符串由m个H和n个D组成,从左到右扫描该串,如果字符H的累计数
总是不小于字符D的累计数,那么,满足条件的字符串总数。

状态转移方程:dp[i+1][j]+=dp[i][j]//在后面加一个H

                    dp[i][j+1]+=d[i][j]//在后面加一个D

#include <cstdio>#include <cstring>#include <cmath>#include <iostream>#include <algorithm>#include <queue>#include <cstdlib>#include <vector>#include <set>#include <map>#define LL long long#define mod 1000000007#define inf 0x3f3f3f3f#define N 10010using namespace std;LL dp[50][50];void init(){    dp[0][0]=1;    for(int i=0;i<=20;i++)    for(int j=0;j<=i;j++)    {        dp[i+1][j]+=dp[i][j];        if(i>j)dp[i][j+1]+=dp[i][j];    }}int main(){    init();    int n,m;    while(scanf("%d%d",&n,&m)>0)    {        printf("%I64d\n",dp[n][m]);    }}
View Code

 

hdu1267(递推)