###### 习题10-5 UVA - 1213 Sum of Different Primes 不同的素数之和（DP + 素数打表）

N不大  小于等于1120

dp[i][j] 表示 选择j 个素数  构成i  方法数。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int maxn = 2000 + 5;
int dp[maxn][maxn/100];
int vis[maxn]; // 0 is prime!
void init(){
int m = sqrt(maxn + 0.5);
for (int i = 2; i <= maxn; ++i) if (!vis[i])
for (int j = i * i; j <= maxn; j += i) vis[j] = 1;
dp[0][0] = 1;
vis[0] = vis[1] = 1;
for (int i = 0; i <= maxn; ++i){
if (vis[i])continue;
for (int j = 14; j >= 1; --j){
for (int k = maxn; k >= i; --k){
dp[k][j] += dp[k-i][j-1];
}
}
}
}
int main(){
init();
int n,k;
while(scanf("%d%d",&n,&k) == 2 && (n||k))
printf("%d\n",dp[n][k]);
return 0;
}


#### UVA 1213 Sum of Different Primes

2015-10-07 15:32:07

#### Sum of Different Primes UVA - 1213 不同素数之和的个数 dp

2017-07-20 17:52:58

#### 习题10-5 不同素数之和 uva 1213

2017-08-14 11:08:28

#### UVA - 1213 Sum of Different Primes 素数＋dp

2017-09-03 13:01:26

#### UVA1213 Sum of Different Primes（素数打表+dp)

2015-05-07 01:18:55

#### LINTCODE——判断k个素数之和

2017-11-22 09:25:25

#### UVA 1213 Sum of Different Primes

2015-10-08 18:48:29

#### UVa 1213 - Sum of Different Primes

2017-06-24 08:52:37

#### 1213 - Sum of Different Primes（DP）

2015-09-05 13:17:18

#### Sum of Different Primes UVA - 1213

2017-11-12 23:20:14