poj 2739 Sum of Consecutive Prime Numbers 素数 读题 难度:0
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 19697 | Accepted: 10800 |
Description
numbers, so neither 7 + 13 nor 3 + 5 + 5 + 7 is a valid representation for the integer 20.
Your mission is to write a program that reports the number of representations for the given positive integer.
Input
Output
Sample Input
2
3
17
41
20
666
12
53
0
Sample Output
1
1
2
3
0
0
1
2 思路:打表,不管是dp还是简单的列举首尾端点
问题:看错题意以为3 5 5 7 是允许的方式
#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(素数) http://poj.org/problem? id=2739 题意: 给你一个10000以内的自然数X.然 ...
- 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( *【素数存表】+暴力枚举 )
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
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 尺取法
Time Limit: 1000MS Memory Limit: 65536K Description Some positive integers can be represented by a ...
- 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 解题报告
题目链接:http://poj.org/problem?id=2739 预处理出所有10001以内的素数,按照递增顺序存入数组prime[1...total].然后依次处理每个测试数据.采用双重循环计 ...
随机推荐
- CodeForces - 343C Read Time (二分+贪心)
题意:有N个指针头,M个标记,用这N个针头扫描所有的标记,针头之间互不影响,求扫描完M个标记的最短时间 分析:二分搜答案,mid为时间限制,则只要所有的点在mid秒内被扫描到即可. 对于每个指针,若其 ...
- SqlHelper简单实现(通过Expression和反射)10.使用方式
以下是整个SqlHelper的Demo: public Result<List<ArticleDTO>> GetIndexArticleList(int count, int ...
- 【二分+SPFA】修建道路(road)
(四五年以前的老草稿,作为强迫症还是发布出来吧) 修建道路(road.pas/c/cpp) [问题描述] NOIP2012的参赛者LG异想天开打算修建一条磁悬浮列车的通道连接现代OI王国的首都(编号为 ...
- motan rpc
git : 帮助 文档 基本介绍 Motan是一套基于java开发的RPC框架,除了常规的点对点调用外,Motan还提供服务治理功能,包括服务节点的自动发现.摘除.高可用和负载均衡等.Motan具有 ...
- ss+proxifier灵活控制网络代理
SS相比大家都知道,不多说. proxifier可能知道的不是很多(至少在今天之前我是不知道的...可能我孤陋寡闻吧) 之前用ss基本上就是chrome SwitchyOmega+SS实现chrome ...
- 枚举转SelectList扩展方法
public enum Avbc { Red=1, Blue=2, Whilt=3, Black=4 } public st ...
- mysql5.6创建索引导致锁表阻塞查询
结论:添加索引时,若果有对该表的慢查询,会导致索引添加延时等待 添加索引语句:alter table tb_name add index idx_xx(col_name); 执行添加索引的SQ ...
- mysql增加远程访问
grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
- windows下Redis主从复制配置(报错:Invalid argument during startup: unknown conf file parameter : slaveof)
主从复制配置中的遇到的异常: Invalid argument during startup: unknown conf file parameter : slaveof 把Redis文件夹复制两份 ...
- 第四篇:Spark SQL Catalyst源码分析之TreeNode Library
/** Spark SQL源码分析系列文章*/ 前几篇文章介绍了Spark SQL的Catalyst的核心运行流程.SqlParser,和Analyzer,本来打算直接写Optimizer的,但是发现 ...