感觉思路可能有点问题,但是加上判断j-pr[i]是否是质数的代码后只有20分了
#include<bits/stdc++.h>
using namespace std;
int n,dp[1010],pr[1000],cnt;
bool is_prime(int n){
for(int i=2;i*i<=n;i++){
if(n%i==0) return false;
}
return true;
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
if(is_prime(i)) pr[++cnt] = i;
}
dp[0] = 1;
for(int i=1;i<=cnt;i++){
for(int j=2;j<=n;j++){
if(j-pr[i]>=0) dp[j] += dp[j-pr[i]];
}
}
cout<<dp[n];
return 0;
}