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 这个 ...
随机推荐
- c#实现Javascript的encodeURIComponent()函数
原文 c#实现Javascript的encodeURIComponent()函数 国内外各搜索引擎,均用JavaScript的encodeURIComponent()函数对搜索关键字进行编码,终于找 ...
- truncate 和 delete 差异
truncate table players; 相当于 delete from players;要么 delete players from players; 要么 delete players.* ...
- 体验魅力Cognos BI 10 系列,第1 部分: 第一次安装
体验魅力Cognos BI 10 系列,第1 部分: 第一次安装吴敏达, 信息管理软件高级技术顾问, IBM简介: 本系列教程旨在帮助您通过实际动手掌握Cognos BI 10.1 的主要功能.在这一 ...
- ASM - 条件判断
技术交流,DH讲解. 正式之前,我们看看寄存器和CPU的标志位: OD中的截图,下方的CPAZSTDO就是标志位. Delphi的FPU窗口,右边一列就是标志位.为什么要给大家看标志位呢?因为ASM中 ...
- Fedora 17 下安装codeblocks
Fedora 17 下安装codeblocks: 1.直接从yum源安装: sudo yum install codeblocks 2.源码安装 ...
- linux下C/C++IDE比较——Code::Blocks
工欲善其事,必先利其器.用了这么久的linux,现在比较主流的几个C/C++的IDE基本已都用过了,现在来对他们做一下简单的比较. 1.VIM首先要说的是VIM.我认为,VIM只是一个编辑器,不能算是 ...
- Javascript/Jquery——简单定时器
第一种方法: <%@ page language="java" contentType="text/html; charset=UTF-8"pageEnc ...
- 慎得慌二u赫然共和任务i个屁
http://www.huihui.cn/share/8424421 http://www.huihui.cn/share/8424375 http://www.huihui.cn/share/842 ...
- hdu 4706
注意一点 空的地方打空格而不是空字符,我因为这wa了一次... #include<cstdio> #include<cstring> #include<cstdlib&g ...
- Swift - 给表格添加Cell的显示动画(3D缩放)
下面的一个样例是让tableView显示数据的时候具有一个很炫的3D缩放效果. 我们只需要实现tableView的willDisplayCell方法.看方法名就知道这是在Cell将要显示的时候执行的方 ...