sgu 116 Index of super-prime
题意:用最少的super-prime组成n;
找出所有的super-prime数,只有202个。用完全背包记录能取到n值的最少数量。再找出7要哪些元素。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <cassert>
using namespace std;
const double EPS=1e-;
const int SZ=,INF=0x7FFFFFFF;
typedef long long lon;
bool p[SZ];
int sz,pri[SZ],spr[SZ],ssz;
set<int> st;
int dp[][SZ]; void init()
{
memset(p,,sizeof(p));
for(int i=;i<SZ;++i)
{
if(p[i])
{
for(int j=i*i;j<SZ;j+=i)p[j]=;
pri[++sz]=i;
st.insert(i);
}
}
for(int i=;i<=sz;++i)
{
if(st.find(i)!=st.end())spr[++ssz]=pri[i];
}
} void show(int r,int c)
{
for(int i=;i<=r;++i)
{
for(int j=;j<=c;++j)
{
cout<<dp[i][j]<<" ";
}cout<<endl;
}
} void work(int x)
{
memset(dp,-,sizeof(dp));
int pos=;
dp[][]=;
for(int i=;i<=ssz;++i)
{
if(spr[i]<=x)pos=i;
else break;
for(int j=;j<=x;++j)
{
dp[i][j]=dp[i-][j];
if(j>=spr[i]&&dp[i][j-spr[i]]!=-)
{
//if(i==1)cout<<j<<" "<<dp[i][j-spr[i]]<<endl;
if(dp[i-][j]==-)dp[i][j]=dp[i][j-spr[i]]+;
else dp[i][j]=min(dp[i][j],dp[i][j-spr[i]]+);
}
}
}
//show(pos,x);
//if(x!=6)for(;;);
if(dp[pos][x]==-)
{//if(x!=6)for(;;);
cout<<""<<endl;
return;
}
//if(x!=6)for(;;);
vector<int> res;
for(int i=pos,j=x;i>=&&j>;)
{
if(j>=spr[i]&&dp[i][j-spr[i]]+==dp[i][j])
{
res.push_back(spr[i]);
j-=spr[i];
}
else --i;
} {
cout<<dp[pos][x]<<endl;
for(int i=;i<res.size();++i)
{
if(i)cout<<' ';
cout<<res[i];
}
} } int main()
{
std::ios::sync_with_stdio();
//freopen("d:\\1.txt","r",stdin);
init();
//cout<<ssz<<endl;
int n;
cin>>n;
work(n);
return ;
}
sgu 116 Index of super-prime的更多相关文章
- 素数 + 背包 - SGU 116. Index of super-prime
Index of super-prime Problem's Link Mean: 如果一个素数所在的位置还是素数,那么这个素数就是超级素数,比如3在第2位置,那么3就是超级素数. 现在给你一个数,求 ...
- Index of super-prime - SGU 116(素数+背包)
题目大意:素数表2,3,5,7,11.....如果一个素数所在的位置还是素数,那么这个素数就是超级素数,比如3在第2位置,那么3就是超级素数.....现在给你一个数,求出来这个数由最少的超级素数的和组 ...
- SGU 106.Index of super-prime
时间限制:0.25s 空间限制:4M 题目大意: 在从下标1开始素数表里,下标为素数的素数,称为超级素数(Super-prime),给出一个n(n<=10000) ...
- SGU 分类
http://acm.sgu.ru/problemset.php?contest=0&volume=1 101 Domino 欧拉路 102 Coprime 枚举/数学方法 103 Traff ...
- 快速切题 sgu116. Index of super-prime bfs+树思想
116. Index of super-prime time limit per test: 0.25 sec. memory limit per test: 4096 KB Let P1, P2, ...
- Python 之 super & MRO (没有遇到过适用场景)
WOW!!! 这里wow的是真尼玛绕且没看完, 好困呐,贴上网址,等自己英文好一点再看(https://rhettinger.wordpress.com/2011/05/26/super-consid ...
- UESTC 1272 Final Pan's prime numbers(乱搞)
题目链接 Description Final Pan likes prime numbers very much. One day, he want to find the super prime n ...
- poj 1595 Prime Cuts
Prime Cuts Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 10610 Accepted: 4046 Descr ...
- Application Error - The connection to the server was unsuccessful. (file:///android_asset/www/index.html)
问题描述: PhoneGap+Sencha Touch开发的应用,打包后的APP或者调试期间,在启动的时候提示如下信息: Application Error - The connection to t ...
随机推荐
- Linux服务器---安装apache
Apache安装 1.安装Apache,使用命令“yum install httpd -y” [root@localhost ~]# yum install httpd -y Loaded pl ...
- iPhone手机获取uuid 安装测试app
iPhone手机获取uuid 安装测试app UDID是一种iOS设备的特殊识别码.除序号之外,每台ios装置都另有一组独一无二的号码,我们就称之为识别码( Unique Device Identif ...
- pbs 作业管理命令
PBS 提供4 条命令用于作业管理. (1) qsub 命令—用于提交作业脚本 命令格式: qsub [-a date_time] [-c interval] [-C directive_prefix ...
- DNS正反向区域解析(二)
域名查询工具 Nslookup命令 >server 202.106.0.20 #指定DNS服务器 >set q=A #指定要查询的类型(A,PTR,MX,CNAME,NS) >www ...
- 2D 2 3D 开源项目
http://www.cvlibs.net/projects.php http://www.cvlibs.net/software/libelas/
- ELK学习笔记之ELK分析syslog日志
0x00 配置FIlebeat搜集syslog并发送至 #配置 mv /etc/filebeat/filebeat.yml /etc/filebeat/filebeat.yml.bak vim /et ...
- 高并发下,php使用uniqid函数生成唯一标识符的四种方案
PHP uniqid()函数可用于生成不重复的唯一标识符,该函数基于微秒级当前时间戳.在高并发或者间隔时长极短(如循环代码)的情况下,会出现大量重复数据.即使使用了第二个参数,也会重复,最好的方案是结 ...
- bzoj1644 / P1649 [USACO07OCT]障碍路线Obstacle Course
P1649 [USACO07OCT]障碍路线Obstacle Course bfs 直接上个bfs 注意luogu的题目和bzoj有不同(bzoj保证有解,还有输入格式不同). #include< ...
- PN结讲解
可能大家在使用半导体器件的时候只是在使用它的电气属性,并没有很好的关心下它是什么原因才有了这样的电气属性,那么我们本篇就从物理结构分析下PN结吧. 首先看一张比较陈旧的图图: (就按自己的笔记简单谈谈 ...
- UVa 10891 Game of Sum - 动态规划
因为数的总和一定,所以用一个人得分越高,那么另一个人的得分越低. 用$dp[i][j]$表示从$[i, j]$开始游戏,先手能够取得的最高分. 转移通过枚举取的数的个数$k$来转移.因为你希望先手得分 ...