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 ...
随机推荐
- 公司里面用的iTextSharp(教程)---生成一个简答的PDF的语法
本来打算先写一个项目大家一起练习的,但是后来发现不懂一些基本的语法,几乎做了之后也有些不明白,下面我们一起简简单单的看一下哈~~ 语法1:Document document = new Documen ...
- SQL学习之SqlMap SQL注入
sqlmap也是渗透中常用的一个注入工具,其实在注入工具方面,一个sqlmap就足够用了,只要你用的熟,秒杀各种工具,只是一个便捷性问题,sql注入另一方面就是手工党了,这个就另当别论了. 今天把我一 ...
- 20145327 《网络对抗》逆向及BOF基础实践
20145327 <网络对抗>逆向及BOF基础实践 实践目标 本次实践的对象是一个名为pwn1的linux可执行文件. 该程序正常执行流程是:main调用foo函数,foo函数会简单回显任 ...
- 骁龙820和KryoCPU:异构计算与定制计算的作用 【转】
本文转载自:https://www.douban.com/group/topic/89037625/ Qualcomm骁龙820处理器专为提供创新用户体验的顶级移动终端而设计.为实现消费者所期望的创新 ...
- OI无关--关于侧边栏
自己在比较闲的时候学了一点html和js,大概能写一些比较简单的东西了,于是就动起了侧边栏的念头. 如果能在博客里加一个题目快速跳转也很兹磁啊. 首先要选择题目,oj的名字肯定是不能直接输入,因为还有 ...
- 使用Android-studio开发移动app与weex结合开发详细步骤
详细步骤如下: 首先,确保机器已经安装了node.js,并且把npm更新到最新版本 下载完毕后,我们可以看到全局目录下的node_modules下面多出一个weex-toolkit 同时,我们留意 ...
- 《EMCAScript6入门》读书笔记——24.编程风格
- ElasticSearch 5.4 安装
1. 前期准备 环境准备 IP地址 操作系统 内存 192.168.1.10 centos 7 16 192.168.1.11 centos 7 16 192.168.1.12 centos ...
- 机器学习-数据可视化神器matplotlib学习之路(四)
今天画一下3D图像,首先的另外引用一个包 from mpl_toolkits.mplot3d import Axes3D,接下来画一个球体,首先来看看球体的参数方程吧 (0≤θ≤2π,0≤φ≤π) 然 ...
- 推荐一个SAM文件中flag含义解释工具--转载
SAM是Sequence Alignment/Map 的缩写.像bwa等软件序列比对结果都会输出这样的文件.samtools网站上有专门的文档介绍SAM文件.具体地址:http://samtools. ...