题意:用最少的super-prime组成n;

找出所有的super-prime数,只有202个。用完全背包记录能取到n值的最少数量。再找出7要哪些元素。

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cmath>
  4. #include <algorithm>
  5. #include <vector>
  6. #include <iomanip>
  7. #include <cstring>
  8. #include <map>
  9. #include <queue>
  10. #include <set>
  11. #include <cassert>
  12. using namespace std;
  13. const double EPS=1e-;
  14. const int SZ=,INF=0x7FFFFFFF;
  15. typedef long long lon;
  16. bool p[SZ];
  17. int sz,pri[SZ],spr[SZ],ssz;
  18. set<int> st;
  19. int dp[][SZ];
  20.  
  21. void init()
  22. {
  23. memset(p,,sizeof(p));
  24. for(int i=;i<SZ;++i)
  25. {
  26. if(p[i])
  27. {
  28. for(int j=i*i;j<SZ;j+=i)p[j]=;
  29. pri[++sz]=i;
  30. st.insert(i);
  31. }
  32. }
  33. for(int i=;i<=sz;++i)
  34. {
  35. if(st.find(i)!=st.end())spr[++ssz]=pri[i];
  36. }
  37. }
  38.  
  39. void show(int r,int c)
  40. {
  41. for(int i=;i<=r;++i)
  42. {
  43. for(int j=;j<=c;++j)
  44. {
  45. cout<<dp[i][j]<<" ";
  46. }cout<<endl;
  47. }
  48. }
  49.  
  50. void work(int x)
  51. {
  52. memset(dp,-,sizeof(dp));
  53. int pos=;
  54. dp[][]=;
  55. for(int i=;i<=ssz;++i)
  56. {
  57. if(spr[i]<=x)pos=i;
  58. else break;
  59. for(int j=;j<=x;++j)
  60. {
  61. dp[i][j]=dp[i-][j];
  62. if(j>=spr[i]&&dp[i][j-spr[i]]!=-)
  63. {
  64. //if(i==1)cout<<j<<" "<<dp[i][j-spr[i]]<<endl;
  65. if(dp[i-][j]==-)dp[i][j]=dp[i][j-spr[i]]+;
  66. else dp[i][j]=min(dp[i][j],dp[i][j-spr[i]]+);
  67. }
  68. }
  69. }
  70. //show(pos,x);
  71. //if(x!=6)for(;;);
  72. if(dp[pos][x]==-)
  73. {//if(x!=6)for(;;);
  74. cout<<""<<endl;
  75. return;
  76. }
  77. //if(x!=6)for(;;);
  78. vector<int> res;
  79. for(int i=pos,j=x;i>=&&j>;)
  80. {
  81. if(j>=spr[i]&&dp[i][j-spr[i]]+==dp[i][j])
  82. {
  83. res.push_back(spr[i]);
  84. j-=spr[i];
  85. }
  86. else --i;
  87. }
  88.  
  89. {
  90. cout<<dp[pos][x]<<endl;
  91. for(int i=;i<res.size();++i)
  92. {
  93. if(i)cout<<' ';
  94. cout<<res[i];
  95. }
  96. }
  97.  
  98. }
  99.  
  100. int main()
  101. {
  102. std::ios::sync_with_stdio();
  103. //freopen("d:\\1.txt","r",stdin);
  104. init();
  105. //cout<<ssz<<endl;
  106. int n;
  107. cin>>n;
  108. work(n);
  109. return ;
  110. }

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. 无法在web服务器下启动调试

    VS2013 编译时异常 无法在web服务器下启动调试.该Web服务器未及时响应   VS2013 编译时错误 无法在web服务器上启动调试.该Web服务器未及时响应.无法在web服务器上启动调试.该 ...

  2. 论文笔记:2018 PRCV 顶会顶刊墙展

    Global Gated Mixture of Second-order Pooling for Imporving Deep Convolutional Neural Network(2018 NI ...

  3. web前端----jQuery扩展(很重要!!)

    1.jQuery扩展语法 把扩展的内容就可以写到xxxx.js文件了,在主文件中直接导入就行了. 用法1.$.xxx() $.extend({ "GDP": function () ...

  4. 推荐:Java性能优化系列集锦

    Java性能问题一直困扰着广大程序员,由于平台复杂性,要定位问题,找出其根源确实很难.随着10多年Java平台的改进以及新出现的多核多处理器,Java软件的性能和扩展性已经今非昔比了.现代JVM持续演 ...

  5. Python3 爬取微信好友基本信息,并进行数据清洗

    Python3 爬取微信好友基本信息,并进行数据清洗 1,登录获取好友基础信息: 好友的获取方法为get_friends,将会返回完整的好友列表. 其中每个好友为一个字典 列表的第一项为本人的账号信息 ...

  6. Java并发之FairSync和NonfairSync

    Java并发中的fairSync和NonfairSync主要区别为: 如果当前线程不是锁的占有者,则NonfairSync并不判断是否有等待队列,直接使用compareAndSwap去进行锁的占用; ...

  7. 解决国内 NPM 安装依赖速度慢问题

    不知道各位是否遇到这种情况,使用NPM(Node.js包管理工具)安装依赖时速度特别慢,为了安装Express,执行命令后两个多小时都没安装成功,最后只能取消安装,笔者20M带宽,应该不是我网络的原因 ...

  8. Educational Codeforces Round 21 Problem E(Codeforces 808E) - 动态规划 - 贪心

    After several latest reforms many tourists are planning to visit Berland, and Berland people underst ...

  9. VC++ 利用CreateFile、ReadFile和WriteFile实现CopyFile

    1. CreateFile:这是一个多功能的函数,可打开或创建以下对象,并返回可访问的句柄:控制台,通信资源,目录(只读打开),磁盘驱动器,文件,邮槽,管道. 参照:http://www.cppblo ...

  10. Python3基础 str translate 将指定字符转换成另一种特定字符

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...