5 POJ 3132 Sum of Different Primes
来源:互联网 发布:win10 不允许下载软件 编辑:程序博客网 时间:2024/04/29 13:08
dp[j][k]表示用j个质数表示k这个值得方法数。
一个质数只能用一次,类似01背包。
#include<cstdio>#include<cstring>const int maxn=1130;int pri[maxn+10],dp[20][maxn+10];void init(){ int i,j; for(i=0;i<=maxn;i++) pri[i]=1; pri[0]=pri[1]=0; for(i=2;i<=maxn;i++) { if(!pri[i]) continue; for(j=i+i;j<=maxn;j+=i) pri[j]=0; }}int main(){ init(); int i,j,k,m,n; while(scanf("%d%d",&n,&m)&&(n||m)) { memset(dp,0,sizeof dp); dp[0][0]=1; for(i=2;i<=n;i++) { if(!pri[i]) continue; for(k=n;k>=i;k--) for(j=m;j>0;j--) dp[j][k]+=dp[j-1][k-i]; } printf("%d\n",dp[m][n]); } return 0;}
0 0
- 5 POJ 3132 Sum of Different Primes
- POJ 3132 Sum of Different Primes
- Poj 3132 Sum of Different Primes
- DP Sum of Different Primes POJ 3132
- POJ 3132 Sum of Different Primes
- poj 3132 Sum of Different Primes
- POJ 3132 Sum of Different Primes
- POJ 3132 Sum of Different Primes
- POJ 3132 Sum of Different Primes 笔记
- 【01背包方案数】POJ-3132 Sum of Different Primes
- POJ 3132 & ZOJ 2822 Sum of Different Primes(dp)
- poj 3132 Sum of Different Primes(01背包)
- POJ 3132 Sum of Different Primes 【01背包】
- Sum of Different Primes
- UVa1213 Sum of Different Primes
- poj3132 Sum of Different Primes
- poj3132 Sum of Different Primes
- Sum of Different Primes UVA
- Linux程序设计(Linux shell编程的例子:在文件名中写入日期)
- Zerone Premium OpenCart 2.0 主题模板 ABC-0461-01
- Lucky Substrings微软在线测试
- C语言---指针与引用的区别
- 使用Java处理大文件
- 5 POJ 3132 Sum of Different Primes
- 基于ICMP的反弹式木马研究与实现
- Android事件传递机制
- 搜集整理的一些面试经验相关的材料
- PHP MemCached 缓存应用
- 班主任好帮手之统计学生成绩
- linux下mysql的安装
- 查看数据库版本
- 黑马程序员----------------JAVA基础线程