Luo Gu P2563 [AHOI2001] prime and decomposition

Luo Gu P2563 [AHOI2001] prime and decomposition

Description

  • Any natural number n is greater than 1 can be written as a number greater than or equal 2 and less than or equal to n and the number of prime expression (including a case where only the number and configuration of expression), and there may be more than one number and the form of quality. For example, prime numbers 9 and expressions of nature there are four different forms:

    9 = 2 + 5 + 2 = 2 + 3 + 2 + 2 = 3 + 3 + 3 = 2 + 7 。

    Here, the term essentially the same expressions are two means can be directly obtained by swapping another expression wherein a position of each number of arithmetic expression and participation.

    Programming try to solve the natural number n How many different prime number and nature of expression can be written.

Input

  • Each line in the file storage a natural number n (2 <n <200).

Output

  • Sequentially outputs each of the different number of essentially natural number prime number n and expressions.

Sample Input

2
200

Sample output

1
9845164

answer

  • Forgive me for the first time did not expect positive solution qwq. My first reaction is to search, but you seem to think carefully find search write to, no idea (I dish it may be). So convert ideas I found that this problem can be so abstract:
    • There is a space for the N package, there are a number of items, the space occupied by each item is a prime number (less than 200), each item can be used unlimited times, will be able to put N bag? Program number is how much?
  • And screen out items Euler available, whether it is put on a packet N is completely streaking backpack. It asked the program to change the number a little bit like (to change the number of feasible solutions)
#include <iostream>
#include <cstdio>
#include <cstring>
#define maxn 205
using namespace std;

int T, n;
int pri[maxn], w[maxn], dp[maxn];
bool flag[maxn] = {1, 1};

int main()
{
    for(int i = 2; i <= 200; i++)
    {
        if(!flag[i]) pri[++n] = i;
        for(int j = 1; j <= n && pri[j] * i <= 200; j++)
        {
            flag[pri[j] * i] = 1;
            if(i % pri[j] == 0) break;
        }
    }
    for(int i = 1; i <= n; i++) w[i] = pri[i];
    while(scanf("%d", &T) != EOF)
    {
        memset(dp, 0, sizeof(dp));
        dp[0] = 1;
        for(int i = 1; i <= n; i++)
            for(int j = w[i]; j <= T; j++)
                dp[j] += dp[j - w[i]];
        cout << dp[T] << endl;
    }
    return 0;
}

Guess you like

Origin www.cnblogs.com/BigYellowDog/p/11122902.html