UVA 1213(p343)----Sum of Different Primes
来源:互联网 发布:ubuntu如何识别u盘 编辑:程序博客网 时间:2024/05/16 07:12
#include<iostream>#include<cstdio>#include<cstring>using namespace std;const int maxn=1120;int u[maxn+50],prime[maxn+50];long long d[20][maxn+50],num,n,k;void get(){ num=1; memset(u,true,sizeof(u)); for(int i=2;i<maxn;i++) { if(u[i]) prime[num++]=i; for(int j=1;j<num;j++) { if(i*prime[j]>maxn) break; u[i*prime[j]]=false; if(i%prime[j]==0) break; } } //for(int i=1;i<num;i++) cout<<i<<" "<<prime[i]<<endl;}void solve(){ d[0][0]=1; for(int i=1;i<num;i++) for(int j=14;j>=1;j--) for(int k=prime[i];k<=maxn;k++) d[j][k]+=d[j-1][k-prime[i]];}int main(){ get(); solve(); /* for(int i=1;i<=14;i++) for(int j=1;j<=5;j++) cout<<i<<" "<<j<<" "<<d[i][j]<<endl;*/ while(scanf("%d%d",&n,&k)!=EOF&&n) printf("%d\n",d[k][n]); return 0;}
0 0
- UVA 1213(p343)----Sum of Different Primes
- UVA 1213 Sum of Different Primes
- UVA 1213 Sum of Different Primes
- uva 1213 Sum of Different Primes, dp
- Sum of Different Primes UVA
- Sum of Different Primes UVA
- uva 1213 sum of different primes 01背包(二维)
- Sum of Different Primes
- 1213 - Sum of Different Primes(DP)
- UVa1213 Sum of Different Primes
- poj3132 Sum of Different Primes
- poj3132 Sum of Different Primes
- WOJ1274-Sum of Different Primes
- UVA 1210(p343)----Sum of Consecutive Prime Numbers
- 习题10-5 UVA - 1213 Sum of Different Primes 不同的素数之和(DP + 素数打表)
- POJ 3132 Sum of Different Primes
- Poj 3132 Sum of Different Primes
- POJ3122 - Sum of Different Primes - 动态规划
- UVA 1210(p343)----Sum of Consecutive Prime Numbers
- PAT (Basic Level) Practise 1002. 写出这个数
- Qt键盘事件
- Eclipse安装SVN教程
- Servlet_04_GenericServlet
- UVA 1213(p343)----Sum of Different Primes
- 关于Assets资源目录结构管理
- Qt中的焦点事件
- Qt::FocusPolicy的使用
- 安装事件过滤器(installEventFilter) ,过滤子控件事件,截获控件按键、鼠标事件
- docker入门
- LeetCode第258题,Add Digits
- 【hdu1181】变形课——bfs
- 武术擂台机器人