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 ...
随机推荐
- Assets.xcassets 应用
1.应用 Assets.xcassets :用来存放图像资源文件 给项目添加 AppIcon 时图标要用 png 格式的,不要用其他格式.当是其它图片格式时 ,不要仅仅修改其后缀名,若仅仅修改后缀名, ...
- linux常用命令:yum 命令
用于添加/删除/更新RPM包,自动解决包的依赖问题以及系统更新升级. 1.命令格式: yum [参数] [软件名]2.命令功能: 功能: yum提供了查找.安装.删除某一个.一组甚至全 ...
- charles破解
替换安装路径->Charles\lib下的charles.jar文件成破解版jar文件,如果再次启动未弹出30天试用的提示,说明破解成功 charles:https://pan.baidu.co ...
- 远程登录 dos命令
1.桌面连接命令 mstsc /v: 192.168.1.250 /console 2.若需要远程启动所有Internet服务,可以使用iisreset命令来实现. 进入“命令提示符”窗口.在提示符后 ...
- TED #10# A rite of passage for late life
Bob Stein: A rite of passage for late life Collection I grew up white, secular and middle class in 1 ...
- 在python3下使用OpenCV 显示图像
在Python3下用使用OpenCV比在C,C++里开发不止快捷一点点, 原型开发的时候蛮有用. 这里用的OpenCV 加载图片, 用的imshow画图 # -*- coding: utf-8 -*- ...
- 20145225唐振遠《网络对抗》Exp5 MSF基础应用
基础问题回答 用自己的话解释什么是exploit,payload,encode? exploit就相当于是载具,将真正要负责攻击的代码传送到靶机中,我觉得老师上课举的火箭和卫星的例子非常形象,火箭只是 ...
- 20144303石宇森《网络对抗》注入shellcode和Return-to-libc攻击
20144303石宇森<网络对抗>PC平台逆向破解 实验1:shellcode注入 实验基础 1.Linux下有两种基本构造攻击buf的方法:retaddr+nop+shellcode,n ...
- 用Win32 实现进度条
转载:http://www.cctry.com/thread-238862-1-1.html #include <windows.h> #include <commctrl.h> ...
- Pandas fillna('Missing')
https://blog.csdn.net/donghf1989/article/details/51167083/ .使用0替代缺失值(当然你可以用任意一个数字代替NaN) df.fillna(0) ...