Topic Portal
Test instructions: A permutation group that is restored after a minimum of k substitutions. Ask for an n element, and in all permutation groups, how many different K.
Analysis: This problem can be translated into: N =σ a I, the LCM ( < Span id= "mathjax-span-10" class= "Mi" >ai ) how many different values are there. For example, when n=10, K can be: 1,2,3,2*2,5,2*3,7,2*2*2,3*3,2*5,2*2*3,2*7,3*5,2*2*5,3*7,2*3*5, a total of 16, here used to : Each natural number greater than 1 can be written as a product of prime numbers, and these factors are arranged by size, only one way. such as: . Then pre-processing the prime number within 1000, Dp[i][j] indicates the use of the first I prime, composed and for J, a prime may be used several times. Because 1 does not affect the result, the result is Σdp[m][i] (m largest prime <=n,i<=n)
Harvest: 1. Permutation group and the unique decomposition Theorem 2. DP and number theory combination
code:
/************************************************* author:running_time* Created time:2015-8-27 18:11:40* File Na Me:f.cpp ************************************************/#include <cstdio> #include <algorithm># Include <iostream> #include <sstream> #include <cstring> #include <cmath> #include <string > #include <vector> #include <queue> #include <deque> #include <stack> #include <list># Include <map> #include <set> #include <bitset> #include <cstdlib> #include <ctime>using namespace std; #define Lson L, Mid, RT << 1#define Rson mid + 1, R, RT << 1 | 1typedef long ll;const int N = 1e3 + 10;const int INF = 0x3f3f3f3f;const int MOD = 1e9 + 7;int prime[n/2];bool is_pri Me[n];ll dp[200][n];int seive (void) {int p = 0;memset (Is_prime, True, sizeof (Is_prime)); for (int i=2; i<=1000; ++i) {if (Is_prime[i]) prime[++p] = i;for (int j=1; j<=p && prime[j]*i<=1000; ++j) {is_PRIME[I*PRIME[J]] = false;if (i% prime[j] = = 0) break;}} return p;} int main (void) {int p = seive (); int n, m = 0;while (scanf ("%d", &n) = = 1) {memset (DP, 0, sizeof (DP));DP [0][0] = 1;for (int i=1; i<=p; ++i) {for (int j=0; j<=n; ++j) dp[i][j] = Dp[i-1][j];int res = prime[i];if (res <= n) m = I;el Sebreak;while (res <= N) {for (int j=0; j+res<=n; ++j) {if (Dp[i-1][j]) dp[i][j+res] + = Dp[i-1][j];} Res *= prime[i];}} ll ans = 0;for (int i=1; i<=n; ++i) ans + = Dp[m][i];p rintf ("%i64d\n", ans + 1);} return 0;}
Number theory +DP hdoj 4345 permutation