首页 > 代码库 > 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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。