素数分解 dp
来源:互联网 发布:百度搜索合作网络 编辑:程序博客网 时间:2024/05/18 09:57
D - 调皮的小明
Time Limit:1000MS Memory Limit:65535KB 64bit IO Format:Description
小明是个数学炒鸡棒的小学生, 精通200以内的加法,老师看不下去了,让小明去自学素数,这不,第二天,小明就回到学校,跟全班同学说他有一个问题,
把一个数分成一个或多个素数的和,有多少种情况。
9 = 2 + 2 + 2 + 3
9 = 2 + 7
9 = 2 + 2 + 5
把一个数分成一个或多个素数的和,有多少种情况。
9 = 2 + 2 + 2 + 3
9 = 2 + 7
9 = 2 + 2 + 5
9 = 3 + 3 + 3
所以有4种。
老师瞬间呆住了,这小明是吃错药了么。。。不过老师还是希望帮小明解决这个题目。请问你能帮助老师吗?答不出来,老师可是要叫家长咯……Input
多组数据,每组数据输入一个N。2<= N <= 200
Output
输出分解的种类数.
Sample Input
89
Sample Output
34#include <cstdio>#include <iostream>#include <algorithm>#include <queue>#include <stack>#include <climits>#include <cstring>#include <cmath>#include <map>#include <set>#define INF 100000000using namespace std;int a[300];int b[300];int dp[210][210];int fun(){for(int i = 2 ;i <= 200;i++){int flag = 0;for(int j = 2;j < i ;j++){if(i%j == 0){a[i] = 0;flag = 1;break;}}if(!flag){a[i] = 1;}}int j = 0;for(int i = 0;i <= 200;i++){if(a[i]){b[j++] = i;}}b[j] = INF;} int main(){fun();memset(dp,0,sizeof(dp));for(int i = 0;i <= 200;i++){dp[0][i] = 1 ;} for(int i = 2;i <= 200;i++){for(int j = 0;b[j] <= 200;j++){if(b[j] > i){dp[i][j] = dp[i][j-1];continue;}if(j == 0){dp[i][j] = dp[i-b[j]][j];}else{dp[i][j] = dp[i-b[j]][j] + dp[i][j-1];}}}int n;while(cin >> n){int i ;for(i = 0;b[i] <= n;i++){}i--;cout << dp[n][i] << endl;}return 0;}
0 0
- 素数分解 dp
- NBUT 1580 素数分解dp
- 素数分解
- 素数分解
- 素数分解
- 素数筛选 素数分解
- 素数和分解
- HDU-1333(素数分解)
- 基础知识-素数分解
- 素数和分解
- HDU1299 素数分解
- 1215 -- 素数分解
- 【lightoj1336】素数分解
- 分解的素数
- 素数分解 (2016_6)
- 素数分解定理
- [Codeforces546D]Soldier and Number Game[dp][实现][素数筛][分解整数][数学]
- 大素数分解与素数判定
- hbase 为什么查询比较快
- _ConnectionPtr _RecordsetPtr CreateInstance失败
- 使用regasm注册.net com组件出现不是有效的.net程序集的解决办法
- PyQt5 来写一个评论框
- html5 based noVNC trial
- 素数分解 dp
- 【Github教程】史上最全github使用方法:github入门到精通
- I.MX6Q(TQIMX6Q/TQE9)学习笔记——新版BSP之u-boot移植
- POJ 3468 A Simple Problem with Integers
- 弹出层
- 栈,堆,全局,文字常量,代码区总结
- 递归回溯法实战(一)——(Red and Black)红黑砖迷阵(POJ1979)
- java.lang.OutOfMemoryError:GC overhead limit exceeded填坑心得
- 最长回文子序列 区间dp