uva10721 Bar Codes(DP)

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

 

#include <iostream>
#define ll long long
using namespace std;
int n,k,m;
ll dp[52][52][52][52][2];
void gao(){
    dp[1][1][1][1][0]=0,dp[1][1][1][1][1]=1;
    for(int i=2;i<=50;i++){
        for(int sum=1;sum<=i;sum++){
            for(int maxl=1;maxl<=i;maxl++){
                for(int nowl=1;nowl<=maxl;nowl++){
                    dp[i][sum][max(maxl,nowl+1)][nowl+1][0]+=dp[i-1][sum][maxl][nowl][0];
                    dp[i][sum+1][maxl][1][1]+=dp[i-1][sum][maxl][nowl][0];
                    dp[i][sum][max(maxl,nowl+1)][nowl+1][1]+=dp[i-1][sum][maxl][nowl][1];
                    dp[i][sum+1][maxl][1][0]+=dp[i-1][sum][maxl][nowl][1];
                }
            }
        }
    }
}
int main(){
    gao();
    while(cin>>n>>k>>m){
        ll ans=0,sum=0;
        for(int j=1;j<=m;j++){
           ans=0;
           for(int i=1;i<=j;i++){
              ans+=dp[n][k][j][i][0]+dp[n][k][j][i][1];
           }
           sum+=ans;
        }
        cout<<sum<<endl;
    }
    return 0;
}
uva10721

 

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