zoj 2822 Sum of Different Primes (01背包)
///给你n 求他能分解成多少个的不同的k个素数相加之和
///01背包,素数打表
# include <stdio.h>
# include <algorithm>
# include <string.h>
# include <math.h>
# include <iostream>
using namespace std;
int cot;
int used[1500];
int prime[1500];
void sushu()///素数打表
{
memset(used,0,sizeof(used));
cot=0;
for(int i=2; i<=1120; i++)
{
if(!used[i])
{
prime[cot++]=i;
for(int j=2*i; j<=1120; j+=i)
used[j]=1;
}
}
}
int main()
{
int n,k,i,j,p;
int dp[1500][20];
while(~scanf("%d %d",&n,&k),n+k)
{
sushu();
memset(dp,0,sizeof(dp));
///01背包
dp[0][0]=1;
for(i=0;i<cot;i++)
{
for(j=k;j>=1;j--)
{
for(p=n;p>=prime[i];p--)
dp[p][j]+=dp[p-prime[i]][j-1];
}
}
printf("%d\n",dp[n][k]);
}
return 0;
}
zoj 2822 Sum of Different Primes (01背包)的更多相关文章
- POJ 3132 & ZOJ 2822 Sum of Different Primes(dp)
题目链接: POJ:id=3132">http://poj.org/problem?id=3132 ZOJ:http://acm.zju.edu.cn/onlinejudge/show ...
- ZOJ - 3956 Course Selection System 【01背包变形】
题目链接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3956 题意 给出N组Hi Ci 然后 要选出若干个 使得 这个式 ...
- ZOJ 3703 Happy Programming Contest(0-1背包)
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3703 Happy Programming Contest Time Lim ...
- uva 624 CD (01背包)
CD You have a long drive by car ahead. You have a tape recorder, but unfortunately your best musi ...
- [UVa1213]Sum of Different Primes(递推,01背包)
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- 2018.08.10 atcoder Median Sum(01背包)
传送门 题意简述:输入一个数组an" role="presentation" style="position: relative;">anan. ...
- Codeforces Round #319 (Div. 2) B. Modulo Sum 抽屉原理+01背包
B. Modulo Sum time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- ZOJ 3956 Course Selection System [01背包]
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3956 题意:就是给你Hi,Ci的值,问怎么取使得下面那个式子的值最大: 理 ...
- Course Selection System ZOJ - 3956 01背包+思维
Course Selection System ZOJ - 3956 这个题目居然是一个01背包,我觉得好难想啊,根本就没有想到. 这个题目把题目给的转化为 ans = a*a-a*b-b*b 这个 ...
随机推荐
- inner join、left join、right join中where和and的作用
inner join.left join.right join中where和and的作用 .内连接(自然连接): 只有两个表相匹配的行才能在结果集中出现 2.外连接: 包括 (1)左外连接 (左边的 ...
- UML建模技术(资料汇总)
其实,我是非常不喜欢,<深入浅出XXX>.<初级入门XXX>,<21天学会XXX>. ... .and so on , 之类的东西的. 好吧,只是得承认,有些还是不 ...
- 用内存流 文件流 资源生成客户端(Delphi开源)
正文:很多木马生成器就是用的内存流和文件流生成客户端的,废话不多说了,代码如下: unit Main; interface usesWindows, Messages, SysUtils, Varia ...
- 表likp新增第一次过账输入日期字段,vl02n/vl01n/vl03n/vl06o的增强
在程序:MV50AFZ1的 FORM USEREXIT_SAVE_DOCUMENT_PREPARE. *begin of ADD CRQ000000012135 CAIZJIAN 2014/3/25( ...
- hdc和hwnd的区别
句柄概念在WINDOWS编程中是一个很重要的概念,在许多地方都扮演着重要的角色.但由此而产生的句柄概念也大同小异,比如:<<Microsoft Windows 3 Develo ...
- 综述-如何克服HTML5的“性工能”障碍
http://ask.dcloud.net.cn/docs HTML5自出现以来,几经风雨,虽看似很有前途,但实际使用问题太多,DCloud为此踩了无数坑.但我们从未放弃,我们加入了W3C,发起了 H ...
- jeecg智能开发平台参与-2013年度中国优秀开源项目评比
JEECG正在参与<2013年度中国十大优秀开源项目> 评比,如果大家觉得JEECG还不错, 请投出你宝贵的一票,给我们以支持吧!!! [目前排名第8位] https://code.csd ...
- POJ 2632 Crashing Robots (坑爹的模拟题)
Crashing Robots Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6599 Accepted: 2854 D ...
- POJ 1330 Nearest Common Ancestors(Tarjan离线LCA)
Description A rooted tree is a well-known data structure in computer science and engineering. An exa ...
- 在MFC程序中使用XML文件配置工具栏
现在我发现使用Visual Studio的资源编辑器进行编辑资源有着诸多的不便:首先是任何资源的变动一般变动代码,不利于系统维护,其次Visual Studio的资源编辑器的本身的功能有限,也不利于界 ...