POJ 2739 Sum of Consecutive Prime Numbers 难度:0
题目链接:http://poj.org/problem?id=2739
#include <cstdio>
#include <cstring>
using namespace std;
int method[10001][1300];
int dp[10001];
bool isntprime[10001];
int heap[1300],cnt;
void calprime(){
method[2][0]=1;
dp[2]++;
heap[cnt++]=2;
for(int i=3;i<10001;i+=2){
if(!isntprime[i]){
heap[cnt]=i;
method[i][cnt++]=1;dp[i]++;
for(int j=3;i*j<10001;j+=2){
isntprime[i*j]=true;
}
}
}
}
void caldp(){
for(int i=2;i<10001;i++){
for(int j=0;j<cnt;j++){
if(method[i][j]!=0){
if(j<cnt-1&&i+heap[j+1]<10001){
method[i+heap[j+1]][j+1]+=method[i][j];
dp[i+heap[j+1]]+=method[i][j];
}
}
}
}
}
int main(){
calprime();
caldp();
int n;
while(scanf("%d",&n)==1&&n){
printf("%d\n",dp[n]);
}
return 0;
}
POJ 2739 Sum of Consecutive Prime Numbers 难度:0的更多相关文章
- POJ.2739 Sum of Consecutive Prime Numbers(水)
POJ.2739 Sum of Consecutive Prime Numbers(水) 代码总览 #include <cstdio> #include <cstring> # ...
- POJ 2739 Sum of Consecutive Prime Numbers(素数)
POJ 2739 Sum of Consecutive Prime Numbers(素数) http://poj.org/problem? id=2739 题意: 给你一个10000以内的自然数X.然 ...
- poj 2739 Sum of Consecutive Prime Numbers 素数 读题 难度:0
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 19697 ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
- POJ 2739 Sum of Consecutive Prime Numbers(尺取法)
题目链接: 传送门 Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Description S ...
- POJ 2739 Sum of Consecutive Prime Numbers( *【素数存表】+暴力枚举 )
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 19895 ...
- POJ 2739 Sum of Consecutive Prime Numbers【素数打表】
解题思路:给定一个数,判定它由几个连续的素数构成,输出这样的种数 用的筛法素数打表 Sum of Consecutive Prime Numbers Time Limit: 1000MS Memo ...
- poj 2739 Sum of Consecutive Prime Numbers 小结
Description Some positive integers can be represented by a sum of one or more consecutive prime num ...
- poj 2739 Sum of Consecutive Prime Numbers 尺取法
Time Limit: 1000MS Memory Limit: 65536K Description Some positive integers can be represented by a ...
随机推荐
- 初学CDQ分治-NEU1702
关于CDQ分治,首先需要明白分治的复杂度. T(n) = 2T(n/2)+O(kn), T(n) = O(knlogn) T(n) = 2T(n/2)+O(knlogn), T(n) = O(knlo ...
- 使用SurfaceView
一.新建一个工程“LearnSurfaceView” 二.新建一个类“MySurfaceView” public class MySurfaceView extends SurfaceView imp ...
- netbeans for php常用快捷键
文本编辑 复制当前行到上一行/下一行ctl+shf+up 移动当前行到上一行/下一行shf+alt+left/right/down/up 删除当前行ctl+E 生成下一行shf+enter(回车) 大 ...
- python类、对象、方法、属性之类与对象笔记
python中一切皆为对象,所谓对象:我自己就是一个对象,我玩的电脑就是对象,坐着的椅子就是对象,家里养的小狗也是一个对象...... 我们通过描述属性(特征)和行为来描述一个对象的.比如家里的小狗, ...
- CI 学习笔记、记录
[ci框架]ci框架目录结构分析 分类: [CodeIgniter深入研究]2013-05-09 00:24 7420人阅读 评论(5) 收藏 举报 [php] view plaincopy mysh ...
- python操作mongodb之五大量写操作
import pymongo #库名 db = pymongo.MongoClient('192.168.30.252',27017).bulk_example #test集合插入 db.test.i ...
- commonJS — 浏览器操作(for Browser)
for Browser github: https://github.com/laixiangran/commonJS/blob/master/src/forBrowser.js 代码 /** * C ...
- Machine Learning - 第4周(Neural Networks: Representation)
Neural networks is a model inspired by how the brain works. It is widely used today in many applicat ...
- GoF--单例设计模式
保证一个类仅有一个实例,并提供一个访问它的全局访问点
- webstorm注释写出的提示
写出这种代码提示的方法是 在一个函数上方打出 /** 然后敲回车就出出来 没达到上面的效果,自己手动写上即可. 这样的好处是: 当你写代码用到此方法的时候会有参数类型提示,如图