首页 > 代码库 > uva11375Dp

uva11375Dp

题意:给你n个火柴问能组成多少种不同的整数。

6个及以上跟棒子的答案要加1 ,算上 0。

#include <cstdio>#include <cstring>#include <algorithm>#include <climits>#include <string>#include <iostream>#include <map>#include <cstdlib>#include <list>#include <set>#include <queue>#include <stack>#include <math.h>using namespace std;const int maxn = 6666;int d[] = { 6, 2, 5, 5, 4, 5, 6, 3, 7, 6 };char dp[maxn][maxn];void gao(char *s1, char *s2){    int a[maxn] = { 0 }; int b[maxn] = { 0 }; int  c[maxn] = { 0 };    int len1 = strlen(s1); int len2 = strlen(s2);    int len = max(len1, len2);    for (int i = 0; i < len1; i++){        a[i] = s1[len1 - 1 - i] - 0;    }    for (int i = 0; i < len2; i++){        b[i] = s2[len2 - i - 1] - 0;    }    for (int i = 0; i < len; i++){        c[i] += a[i] + b[i];        c[i + 1] = c[i] / 10;        c[i] %= 10;    }    len++;    while (!c[len]) len--;    for (int i = 0; i <= len; i++)        s1[i] = c[len - i] + 0;    s1[len + 1] = \0;}int main(){    int n;    dp[0][0] = 1;    dp[0][1] = \0;    for (int i = 0; i <= 2000; i++){        for (int j = 0; j < 10; j++){            if ((i == 0 && j == 0) || i + d[j]>2000)  continue;            gao(dp[i + d[j]], dp[i]);        }    }    char str3[]= {"1"};    gao(dp[6],str3);    for (int i = 2; i <= 2000; i++){        gao(dp[i], dp[i - 1]);    }    while (cin >> n){        if(n==1){            cout<<0<<endl;continue;        }        cout << dp[n] << endl;    }    return 0;}

 

uva11375Dp