标签:dp
Description
9 = 3 + 3 + 3
所以有4种。
老师瞬间呆住了,这小明是吃错药了么。。。不过老师还是希望帮小明解决这个题目。请问你能帮助老师吗?答不出来,老师可是要叫家长咯……Input
Output
Sample Input
8 9
Sample Output
3 4#include <cstdio> #include <iostream> #include <algorithm> #include <queue> #include <stack> #include <climits> #include <cstring> #include <cmath> #include <map> #include <set> #define INF 100000000 using namespace std; int a[300]; int b[300]; int dp[210][210]; int fun(){ for(int i = 2 ;i <= 200;i++){ int flag = 0; for(int j = 2;j < i ;j++){ if(i%j == 0){ a[i] = 0; flag = 1; break; } } if(!flag){ a[i] = 1; } } int j = 0; for(int i = 0;i <= 200;i++){ if(a[i]){ b[j++] = i; } } b[j] = INF; } int main(){ fun(); memset(dp,0,sizeof(dp)); for(int i = 0;i <= 200;i++){ dp[0][i] = 1 ; } for(int i = 2;i <= 200;i++){ for(int j = 0;b[j] <= 200;j++){ if(b[j] > i){ dp[i][j] = dp[i][j-1]; continue; } if(j == 0){ dp[i][j] = dp[i-b[j]][j]; } else{ dp[i][j] = dp[i-b[j]][j] + dp[i][j-1]; } } } int n; while(cin >> n){ int i ; for(i = 0;b[i] <= n;i++){ } i--; cout << dp[n][i] << endl; } return 0; }
标签:dp
原文地址:http://blog.csdn.net/qq_24667639/article/details/45420973