即求P1^n1+P2^n2 + ... + Pk^nk <= n,其中Pk为素数的所有可能组合。
思路是DP。1~1000的素数就不到200个。
dp[i][j]表示上式和不超过且当前最小素数为P[j]的所有可能情况。注意dp[i][0]+1即为所求。

 /* 4345 */
#include <iostream>
#include <sstream>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <deque>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <functional>
#include <iterator>
#include <iomanip>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,1024000") #define sti set<int>
#define stpii set<pair<int, int> >
#define mpii map<int,int>
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define rep(i, a, n) for (int i=a;i<n;++i)
#define per(i, a, n) for (int i=n-1;i>=a;--i)
#define clr clear
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define lson l, mid, rt<<1
#define rson mid+1, r, rt<<1|1 const int maxn = ;
bool isPrime[maxn];
int P[maxn], pn = ;
__int64 dp[maxn][];
__int64 ans[maxn]; void init() {
memset(isPrime, true, sizeof(isPrime));
rep(i, , maxn) {
if (isPrime[i]) {
P[pn++] = i;
for (int j=i*i; j<maxn; j+=i)
isPrime[j] = false;
}
} #ifndef ONLINE_JUDGE
printf("pn = %d\n", pn);
#endif
ans[] = ;
rep(i, , ) {
rep(j, , pn) {
if (P[j] > i)
break;
for (int k=P[j]; k<=i; k*=P[j]) {
dp[i][j] += dp[i-k][j+] + ;
}
}
per(j, , )
dp[i][j] += dp[i][j+];
ans[i] = dp[i][] + ;
} #ifndef ONLINE_JUDGE
rep(i, , )
printf("%d: %I64d\n", i, ans[i]);
#endif
} int main() {
ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif int n; init(); while (scanf("%d", &n)!=EOF)
printf("%I64d\n", ans[n]); #ifndef ONLINE_JUDGE
printf("time = %d.\n", (int)clock());
#endif return ;
}

【HDOJ】4345 Permutation的更多相关文章

  1. 【题解】CF359B Permutation

    [题解]CF359B Permutation 求一个长度为\(2n\)的序列,满足\(\Sigma |a_{2i}-a_{2i-1}|-|\Sigma a_{2i}-a_{2i-1}|=2k\) 这种 ...

  2. 【HDOJ】4985 Little Pony and Permutation

    水题. #include <cstdio> #define MAXN 100005 int buf[MAXN], n; int main() { int i, j, k; while (s ...

  3. 【HDOJ】4729 An Easy Problem for Elfness

    其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到 ...

  4. 【leetcode】Next Permutation

    Next Permutation Implement next permutation, which rearranges numbers into the lexicographically nex ...

  5. 【leetcode】Next Permutation(middle)

    Implement next permutation, which rearranges numbers into the lexicographically next greater permuta ...

  6. 【HDOJ】【3506】Monkey Party

    DP/四边形不等式 裸题环形石子合并…… 拆环为链即可 //HDOJ 3506 #include<cmath> #include<vector> #include<cst ...

  7. 【HDOJ】【3516】Tree Construction

    DP/四边形不等式 这题跟石子合并有点像…… dp[i][j]为将第 i 个点开始的 j 个点合并的最小代价. 易知有 dp[i][j]=min{dp[i][j] , dp[i][k-i+1]+dp[ ...

  8. 【HDOJ】【3480】Division

    DP/四边形不等式 要求将一个可重集S分成M个子集,求子集的极差的平方和最小是多少…… 首先我们先将这N个数排序,容易想到每个自己都对应着这个有序数组中的一段……而不会是互相穿插着= =因为交换一下明 ...

  9. 【HDOJ】【2829】Lawrence

    DP/四边形不等式 做过POJ 1739 邮局那道题后就很容易写出动规方程: dp[i][j]=min{dp[i-1][k]+w[k+1][j]}(表示前 j 个点分成 i 块的最小代价) $w(l, ...

随机推荐

  1. Repeater中将int类型和bool类型的字段以字符显示出来

    图一 图二 比如将图一中是否显示中的列显示以图二中的方式显示: 方法1: 1.在后台编写方法:a.aspx.cs代码如下 //IsShow字段显示的方法public string GetStrIsSh ...

  2. 英文版firefox显示中文字体丑的问题

    在Options里面选择Content,在Fonts&Colors区域的Default font中,选择Times New Roman 如下图1: 在旁边的Advanced中选择,Fonts ...

  3. Winform DataGridView添加列头checkbox

    using System; using System.Data; using System.Drawing; using System.Windows.Forms; using Yanwen.Logi ...

  4. Get code int value for different encoding

    http://msdn.microsoft.com/en-us/library/system.text.encodinginfo.getencoding%28v=vs.110%29.aspx usin ...

  5. laravel扩展Debugbar

    github地址:https://github.com/barryvdh/laravel-debugbar

  6. Inside Microsoft SQL Server 2008: T-SQL Querying 读书笔记1

    (5)SELECT   (5-2) DISTINCT    (5-3)TOP(<top_specifications>)   (5-1)<select_list> (1)FRO ...

  7. delphi调用 java 的 WebService服务端.

    // InvRegistry.RegisterInvokeOptions(TypeInfo(ModelADServicePortType), ioLiteral); InvRegistry.Regis ...

  8. DB2分区表删除和添加分区

    1.数据库版本 2.具体procedure DROP PROCEDURE DB2USER.TOOLS_PARTITION_TABLE_SHOW (VARCHAR ()); )) /********** ...

  9. C++ 容器及选用总结

    目录 ==================================================== 第一章 容器 第二章 Vector和string 第三章 关联容器 第四章 迭代器 第五 ...

  10. 2016 系统设计第一期 (档案一)MVC bootstrap model弹出窗

    局部代码: <!-- 按钮触发模态框 --> <div style=""> <button class="btn btn-primary&q ...