uva10943 How do you add?(DP)

题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=11&page=show_problem&problem=1884

 

#include <iostream>
#include <cstring>
#define mod 1000000
using namespace std;
int dp[110][110];
int DP(int x,int y){
    if(dp[x][y]!=-1) return dp[x][y];
    if(y==1) return dp[x][y]=1;
    int ret=0;
    for(int i=0;i<=x;i++){
       ret+=DP(i,y-1);
       ret%=mod;
    }
    return dp[x][y]=ret%mod;
}
int main(){
    int n,k;

    while(cin>>n>>k){
        if(n==0&&k==0) break;
        memset(dp,-1,sizeof dp);
        cout<<DP(n,k)<<endl;
    }
    return 0;
}
uva10943

 

posted @ 2014-02-09 20:39  wonderzy  阅读(133)  评论(0编辑  收藏  举报