题意:用最少的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的更多相关文章

  1. 素数 + 背包 - SGU 116. Index of super-prime

    Index of super-prime Problem's Link Mean: 如果一个素数所在的位置还是素数,那么这个素数就是超级素数,比如3在第2位置,那么3就是超级素数. 现在给你一个数,求 ...

  2. Index of super-prime - SGU 116(素数+背包)

    题目大意:素数表2,3,5,7,11.....如果一个素数所在的位置还是素数,那么这个素数就是超级素数,比如3在第2位置,那么3就是超级素数.....现在给你一个数,求出来这个数由最少的超级素数的和组 ...

  3. SGU 106.Index of super-prime

    时间限制:0.25s 空间限制:4M 题目大意:                 在从下标1开始素数表里,下标为素数的素数,称为超级素数(Super-prime),给出一个n(n<=10000) ...

  4. SGU 分类

    http://acm.sgu.ru/problemset.php?contest=0&volume=1 101 Domino 欧拉路 102 Coprime 枚举/数学方法 103 Traff ...

  5. 快速切题 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, ...

  6. Python 之 super & MRO (没有遇到过适用场景)

    WOW!!! 这里wow的是真尼玛绕且没看完, 好困呐,贴上网址,等自己英文好一点再看(https://rhettinger.wordpress.com/2011/05/26/super-consid ...

  7. 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 ...

  8. poj 1595 Prime Cuts

    Prime Cuts Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 10610   Accepted: 4046 Descr ...

  9. 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 ...

随机推荐

  1. jQuery ajax 请求HttpServlet返回[HTTP/1.1 405 Method not allowed]

    1.问题使用jQuery的ajax请求 Servlet 时,返回没有进入ajax的success回调函数,浏览器控制台显示 [HTTP/1.1 405 Method not allowed]. 2.解 ...

  2. linux常用命令:traceroute 命令

    通过traceroute我们可以知道信息从你的计算机到互联网另一端的主机是走的什么路径.当然每次数据包由某一同样的出发点(source)到达某一同样的目的地(destination)走的路径可能会不一 ...

  3. JVM内存分布

    参考引用文章地址: http://hllvm.group.iteye.com/group/wiki/3053-JVMhttp://blog.csdn.net/william001zs/article/ ...

  4. web前端----JavaScript的DOM(三)

    一.JS中for循环遍历测试 for循环遍历有两种 第一种:是有条件的那种,例如    for(var i = 0;i<ele.length;i++){} 第二种:for (var i in l ...

  5. web前端----css补充

    css常用的一些属性: 1.去掉下划线 :text-decoration:none ;2.加上下划线: text-decoration: underline; 3.调整文本和图片的位置(也就是设置元素 ...

  6. MySQL数据库----数据锁

    数据锁 需求: 有一个账户,两个人在同一时间要对此账户操作,A要对账户充值100块,B要从账户中取出100块.操作前都要先看一下账户的 余额然后再操作. -- 窗口1 用户进行充值 -- 充值前 先查 ...

  7. MySQL数据库----视图

    视图 视图是一个虚拟表(非真实存在),其本质是[根据SQL语句获取动态的数据集,并为其命名],用户使用时只需使用[名称]即可获取结果集,可以将该结果集当做表来使用. 使用视图我们可以把查询过程中的临时 ...

  8. python之路----面向对象中的内置函数

    property属性 什么是特性property property是一种特殊的属性,访问它时会执行一段功能(函数)然后返回值 例一:BMI指数(bmi是计算而来的,但很明显它听起来像是一个属性而非方法 ...

  9. (七)git分支的操作

    1.git branch——显示分支一览表 2.git checkout -b——创建.切换分支 往feature-A中不断add.commit叫培育分支 git checkout - 切回上一个分支 ...

  10. Rubin-Miller与Pollard Rho

    两个没什么卵用的算法. 只放一下模板: BZOJ3667 //BZOJ 3667 //by Cydiater //2017.2.20 #include <iostream> #includ ...