"Hdoj" 4345 permutation

Source: Internet
Author: User

That is, p1^n1+p2^n2 + ... + pk^nk <= N, where Pk is the prime number of all possible combinations.
The idea is DP. There are less than 200 primes in 1~1000.
DP[I][J] represents all possible conditions for the above and not exceeding and the current minimum prime number is p[j]. Note that dp[i][0]+1 is what you ask for.

1 /*4345*/2#include <iostream>3#include <sstream>4#include <string>5#include <map>6#include <queue>7#include <Set>8#include <stack>9#include <vector>Ten#include <deque> One#include <algorithm> A#include <cstdio> -#include <cmath> -#include <ctime> the#include <cstring> -#include <climits> -#include <cctype> -#include <cassert> +#include <functional> -#include <iterator> +#include <iomanip> A using namespacestd; at //#pragma COMMENT (linker, "/stack:102400000,1024000") -  - #defineSTI set<int> - #defineStpii Set<pair<int, int> > - #defineMpii map<int,int> - #defineVI vector<int> in #definePII pair<int,int> - #defineVpii vector<pair<int,int> > to #defineRep (I, A, n) for (int i=a;i<n;++i) + #definePer (i, a, n) for (int i=n-1;i>=a;--i) - #defineCLR Clear the #definePB Push_back * #defineMP Make_pair $ #defineFIR FirstPanax Notoginseng #defineSEC Second - #defineAll (x) (x). Begin (), (x). End () the #defineSZ (x) ((int) (x). Size ()) + #defineLson L, Mid, rt<<1 A #defineRson mid+1, R, rt<<1|1 the  + Const intMAXN =1005; - BOOLISPRIME[MAXN]; $ intP[MAXN], PN =0; $__int64 dp[maxn][205]; - __int64 ANS[MAXN]; -  the voidinit () { -memset (IsPrime,true,sizeof(IsPrime));WuyiRep (I,2, MAXN) { the         if(Isprime[i]) { -p[pn++] =i; Wu              for(intJ=i*i; j<maxn; j+=i) -ISPRIME[J] =false; About         } $     } -      - #ifndef Online_judge -printf"pn =%d\n", PN); A     #endif +ans[1] =1; theRep (I,2,1001) { -Rep (J,0, PN) { $             if(P[j] >i) the                  Break; the              for(intK=P[J]; k<=i; k*=P[j]) { theDP[I][J] + = dp[i-k][j+1] +1; the             } -         } inPer (J,0, $) theDP[I][J] + = dp[i][j+1]; theAns[i] = dp[i][0] +1; About     } the      the #ifndef Online_judge theRep (I,1,1001) +printf"%d:%i64d\n", I, ans[i]); -     #endif the }Bayi  the intMain () { theIos::sync_with_stdio (false); - #ifndef Online_judge -Freopen ("data.in","R", stdin); theFreopen ("Data.out","W", stdout); the     #endif the      the     intN; -      the init (); the      the      while(SCANF ("%d", &n)! =EOF)94printf"%i64d\n", Ans[n]); the      the #ifndef Online_judge theprintf"Time =%d.\n", (int) clock ());98     #endif About      -     return 0;101}

"Hdoj" 4345 permutation

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.