Prime Decomposition DP

Source: Internet
Author: User

D-Naughty xiaoming.Time limit:MS Memory Limit:65535KB 64bit IO Format:SubmitStatusPracticenbut 1580

Description

Xiao Ming is a math fried chicken sticks of elementary school students, proficient in 200 of the addition, the teacher can not see down, let Xiao Ming to self-study prime, this is not, the next day, Xiao Ming back to school, with the whole class said he had a problem,
Divide a number into one or more primes, and how many cases.
9 = 2 + 2 + 2 + 3
9 = 2 + 7
9 = 2 + 2 + 5

9 = 3 + 3 + 3

So there are 4 kinds.

The teacher momentarily stay, this Xiao Ming is to eat the wrong medicine ... But the teacher still hope to help Xiao Ming solve this problem. Can you help the teacher, please? Can't answer, the teacher is to call parents ...

Input

Multiple sets of data, one n for each set of data. 2<= N <= 200

Output

The number of types of output decomposition.

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;} 


Prime number decomposition DP

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.