![](https://img-blog.csdnimg.cn/20201014180756754.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
动态规则
文章平均质量分 59
birdforever
我是一个纯粹的人,生不带来,死不带走,只为无怨无悔地活一次!
展开
-
poj 1276 Cash Machine
<br /> <br />/*<br />多重背包问题,本题如不使用二进制分物品可能会超时,<br />毕竟数目不小。另一个要注意的点是不用考虑找的最少钱数,<br />只要能找出钱就行了,因此用0和1(dp[0]=1)赋值就行了,如<br />果能找到钱就赋非0值,结果输出dp值为非0的最大数就行了。<br />*/<br />#include <cstdio><br />int value[100];<br />int dp[100010];<br />int main()<br />{<br /> i原创 2010-08-27 19:04:00 · 390 阅读 · 0 评论 -
poj 1038 Bugs Integrated, Inc.
<br />//poj 1038 状态DP<br />//思路源于解题报告:http://hi.baidu.com/lewutian/blog/item/0146f22706ba4108918f9da8.html,刘汝佳黑书也有本题题解<br />//PS: 此题做了一个通宵,只是因为一直不肯放弃自己原来的二进制的做法,做到四点多才改成三进制.现在的水平,变通对我来说太难<br />//了。。。<br />#include <cstring><br />#include <iostream><br />#i原创 2010-09-02 16:09:00 · 1780 阅读 · 0 评论 -
poj 1015 Jury Compromise
<br />//poj 1015 相当经典的DP题。题意其实就是给一个n个整数的序列(可负),要求取出m个,使得这m个的整数和<br />//绝对值最小,而且Sum(di)+Sum(pi)最大。而且要求记录最优解的路径。<br /><br />#include <iostream><br />#include <algorithm><br />using namespace std;<br />int n,m;<br />int d[205],p[205]; //本题的整数就是用d[i]-p[i]表示<b原创 2010-09-03 12:14:00 · 1348 阅读 · 1 评论 -
poj 1848 Tree
<br />//poj 1848 Tree (树型DP)<br />//很详细的解题报告:http://hi.baidu.com/19930705cxjff/blog/item/1df66e4a4ff3022e08f7ef5d.html<br /> <br />#include <cstring><br />#include <iostream><br />#include <algorithm><br />#include <vector><br />using namespace std;<br />c原创 2010-09-02 16:03:00 · 957 阅读 · 0 评论 -
poj 1946 Cow Cycling
<br />//poj 1946 经典DP<br />/*<br />对于一直骑行在非队首的选手,能量消耗和距离是相等的,这给了我们用DP来处理的条件。<br />DP[i][j]表示i个人骑行距离j的最短时间。<br />于是有DP[i][k]=DP[i-1][j]+min_time(E-(d-k),k-j)(0<k<=d,0<=j<k),min_time(i,j)表示队首的人有能量i,骑行距离j的最短时间。通过观察可以发现,对于给定的距离d个时间t,总是把d划分为尽量相等的t段时消耗的能量较少,这也即是原创 2010-09-02 16:04:00 · 819 阅读 · 0 评论 -
poj 1014 Dividing
//poj 1014 Dividing 也有人用搜索做,本人觉得是比较基础的背包题,不过要加二进制的优化。#include #include using namespace std;int a[7];int b[10000];int dp[60000];int main(){ for (int tm=1;;++tm) { int sum=0; bool flag=true;原创 2010-09-03 12:11:00 · 557 阅读 · 0 评论 -
poj 1185 炮兵阵地
//poj 1185 炮兵阵地/*又一道状态压缩DP ,最烦的题,没心思精简代码,1700多MS低空飞过。。。 */ #includeusing namespace std;int n,m;char str[12];int grid[102];int dp[101][70][70]; //dp[n][i][j]表示d到第n行,第n行和第n-1行分别为状态i,j的最大炮兵数。 int state[70],c;//dfs一遍把所有状态记录下来,由于限制大,所原创 2010-09-05 17:27:00 · 404 阅读 · 0 评论 -
poj 1037 A decorative fence
<br />//poj 1037 A decorative fence 经典的DP+计数/* 题解:dp[len][i][0]表示长度为len的序列,第i长的棒起头,前两根下降的方案数;dp[len][i][1]表示相应的前两根上升的方案数 只要想到方案中只要求交替上升下降,只与长度的相对高低有关系就不难想出这样的dp方法了。预处理完后就是一般的计数方法了。心得:本题又暴露出自己的不自信,明明是正确的方法,只是实现上出现也小bug,就怀疑自己。看来心理素质还是比较重要。*/原创 2010-09-05 17:34:00 · 1879 阅读 · 1 评论 -
poj 1322 Chocolate
<br />//poj 1322 Chocolate DP/*一个很显然的事实是,在某时刻,桌子上任意两根头发的颜色一定都不相同。令f[i][j]表示i次操作后,桌子上有j根头发的概率。对于每个f[i][j]:若新拔下的头发与目前桌子上的头发颜色都不相同(概率为(c-j)/c),那么f[i+1][j+1]+=f[i][j]*(c-j)/c。若新拔下的头发与目前桌子上的某根头发颜色相同(概率为j/c),那么f[i+1][j-1]+=f[i][j]*j/c。初始化f[0][0]=1,f[原创 2010-09-07 16:56:00 · 1403 阅读 · 1 评论 -
poj 1082 Calendar Game
<br />//poj 1082 Calendar Game (DP/博弈)/*题解:预处理一下从1900.1.1-2001.11.4之间的每一天开始,Adam先走或后走的胜利者。 dp[year][month][day][1]表示year.month.day这一天Adam先走的胜者,1为Adam胜,0为Adam输。 决策题目中已给出最多两种:加一天或者加一个月,只要有一个决策能够使Adam胜出,Adam在这 一天就可以胜出。PS: 注意一下闰年和每月天原创 2010-09-07 17:02:00 · 108 阅读 · 0 评论 -
poj 1155 TELE
<br />/* source code of submission 401148, Zhongshan University Online Judge System */ //树型DP #include #include #include #include using namespace std; const int size=3000; const int inf=1<<28; int n,m; //POJ1155 树型DP struct node { int adj; int wt; node(){}原创 2010-09-01 21:39:00 · 583 阅读 · 0 评论 -
poj 1390 Blocks
<br />//poj 1390 解法很巧妙,见lrj黑书。。。<br />#include <iostream><br />#include <algorithm><br />using namespace std;<br /><br />int n,m;<br />int color[205],len[205];<br />int dp[205][205][205];<br />int after[205];<br />int main()<br />{<br /> int t,a;<br />原创 2010-09-03 12:15:00 · 833 阅读 · 0 评论 -
poj 1192 最优连通子集
<br />//poj 1192 最优连通子集 (树型DP)/*题意:给定一个平面整点集,点与点间在|x1-x2| + |y1-y2| = 1时相邻,且形成的图没有回路, 每个点有一个可正可负的权值,求最大权和连通子图。题解:树型DP,dp[i][0]表示以i为根的子树上不包括i的最大权和,dp[i][1]表示包括i的最大权和。*/#include <iostream>#include <algorithm>#include <cmath>#include <v原创 2010-09-09 22:50:00 · 1911 阅读 · 1 评论 -
usaco 4.3(经典LIS模板)
<br />/* ID: majunch2 LANG: C++ PROG: buylow*///usaco 4.3//很经典的O(nlogn)LIS问题,还可以求序列方案数#include <cstdio>#include <cstdlib>#include <cstring>//#include <cmath>#include <algorithm>//#include <ctime>using namespace std;con原创 2010-09-12 15:58:00 · 920 阅读 · 1 评论 -
poj 1160 Post Office
<br />//POJ 1160 解题报告:(引用以下两位大牛,写得不错)<br />//http://www.608088.com/show-51-1.html<br />//http://hi.baidu.com/rain_bow_joy/blog/item/ba85e922219b455b9822edfd.html<br />#include <cstdio><br />#include <cmath><br />int dist[310][310];<br />int v[310];<br />in原创 2010-08-27 19:10:00 · 379 阅读 · 0 评论 -
poj 1088 滑雪
<br />//如果这道题用暴力搜索,可以AC,但要花四百多ms<br />#include <cstdio><br /><br />int height[110][110];<br />int wt[110][110];<br />int main()<br />{<br /> int r,c;<br /> int sum=0,minx=0,miny=0;<br /> scanf("%d%d",&r,&c);<br /> for (int i=0;i<r;i++)<br /> for (int j=0;原创 2010-08-27 19:11:00 · 409 阅读 · 0 评论 -
poj 1695 Magazine Delivery
<br />//POJ1695<br />#include <cstdio><br />#include <cstring><br />using namespace std;<br />int dp[32][32][32];<br />int dist[32][32];<br />int main()<br />{<br /> int t,n;<br /> scanf("%d",&t);<br /> while(t--)<br /> {<br /> scanf("%d",&n);<br /> for原创 2010-08-30 00:26:00 · 506 阅读 · 0 评论 -
poj 1549
<br />#include <iostream><br />#include <cstdlib><br />#include <cmath><br />#include <algorithm><br />using namespace std;<br />const int inf=1<<28;<br />//poj 1549<br />int b[8];<br />char input[12][10];<br />int brac[12][10];<br />int ans[15];<br />int原创 2010-08-31 21:08:00 · 616 阅读 · 0 评论 -
poj 1179 Polygon
<br />//poj 1179 Polygon (DP)/*题解:矩阵链乘法变型,不过要注意负负得正,两个最小子结果相乘会得到最大正值。PS: 这种题初始化比较烦,所以写得比较简单粗糙,好在数据量不大,16MS。。。*/#include <iostream>#include <algorithm>#include <cmath>using namespace std;const int inf = 1<<28;int n,m;int a[110];char原创 2010-09-11 14:50:00 · 630 阅读 · 0 评论 -
usaco 3.3.5(博弈/DP)
<br />/* ID: majunch2 LANG: C++ PROG: game1*/// usaco 3.3.5/*设 F1[I,J] 为第一个人(先行者) 从I 取到 J 的最大分数 F2[I,J] 为第二个人(先行者) 从I 取到 J 的最大分数 S[I] 为 第 I 张牌的分数..... Sum[I] 为第 1 到第 I 张牌的分数总和.... F1[I,J]=max{ F2[I+1,J]+S[I] , F2[I,J-1]+S[J原创 2010-09-12 16:00:00 · 668 阅读 · 0 评论 -
poj 2288 Islands and Bridges
#include #include #include #include using namespace std;//poj 2288 Islands and Bridgesint n,m;int a[15];int con[15][15];__int64 dp[1ans) { ans=dp[(1原创 2010-09-01 21:38:00 · 469 阅读 · 0 评论 -
poj 1141 Brackets Sequence
<br />// source code of submission 343733, Zhongshan University Online Judge System#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <algorithm>#include <queue>#include <stack>using namespace原创 2010-11-10 21:09:00 · 561 阅读 · 0 评论