DP
文章平均质量分 56
BSOD_aura
这个作者很懒,什么都没留下…
展开
-
HDU 1500 DP
反着存储数据,DP时就不需要考虑第三根筷子了。然后很简单的DP,用滚动数组处理#include "stdio.h"#include "string.h"#include "stdlib.h"#include "math.h"struct comp{ int x[5010];} dp1,dp2;int num[5010];int minn(int x,int原创 2013-10-22 18:36:00 · 613 阅读 · 0 评论 -
ZOJ 3160 区间DP
好久不写DP。。DEBUG了好久。。区间DP的模板题#include "stdio.h"#include "string.h"#include "math.h"#include "stdlib.h"int main(){ int n,m,x,y,k,i,j; int map[310][310]; int dp[310][310]; int a[310]; while原创 2013-11-20 14:07:00 · 895 阅读 · 0 评论 -
HDU 4800 DP
13长沙现场赛DP就是告诉你C(m,3)个队伍相互之间的胜率,然后要你依次对战n个AI队伍,首先任选一种队伍,然后战胜一个AI后可以选择替换成AI的队伍,也可以不换,问你最后最大的胜率是多少。从最后一个对战开始DPdp[i][j]=a[j][b[i]]*max(dp[i+1][j],dp[i+1][b[i]])#include "stdio.h"#incl原创 2013-12-01 12:45:09 · 798 阅读 · 0 评论 -
HDU 1074 状压DP
状态压缩DP 模板感觉叫 状态压缩搜索更合适。。。#include "iostream"#include "algorithm"const int inf=0x7fffffff;struct comp{ char name[101]; int et,cost;} data[21];int b[21],hash[21];int sum[1<<16];// 存储代价cha原创 2014-03-12 16:18:23 · 492 阅读 · 0 评论 -
FZU 2092 记忆化搜索 || BFS
BFS:#include "queue"#include "iostream"#include "algorithm"using namespace std;int dir[5][2]={1,0,-1,0,0,1,0,-1,0,0};int value[12][12][211];int hash[11][11][11][11][210];struct node{ in原创 2014-05-04 09:29:13 · 601 阅读 · 0 评论 -
HDU 1078 记忆化搜索
记忆化搜索模板原创 2014-04-21 14:06:03 · 454 阅读 · 0 评论 -
HDU 1059 背包
#include "stdio.h"#include "string.h"int main(){ int Case,k,key,sum,i,j; int dp[60010]; int a[10]; Case=1; while (scanf("%d",&a[1])!=EOF) { sum=a[1]; for (i=2;i<=6;i++) { scanf("%d"原创 2014-04-21 09:50:43 · 426 阅读 · 0 评论 -
HDU 3336 记忆化搜索
参考这个写的:http://blog.csdn.net/akof1314/article/details/5473837#include "stdio.h"#include "string.h"char str[200010];int b[200010];int main(){ int t,n,ans,k,i,j,m; scanf("%d",&t); while (原创 2014-04-21 15:28:32 · 444 阅读 · 0 评论 -
HDU 1978 DP
简单DP#include "stdio.h"#include "string.h"#include "math.h"int main(){ int t,n,m,i,j,x,y; int a[101][101]; int dp[101][101]; scanf("%d",&t); while (t--) { scanf("%d%d",&n,&m); for (i=1;原创 2014-04-23 10:35:11 · 440 阅读 · 0 评论 -
HDU 2955 背包
背包问题转移方程:原创 2014-04-23 11:49:10 · 474 阅读 · 0 评论 -
HDU 1864 背包
01背包 水注意判断好发票是否可用即可#include "stdio.h"#include "math.h"#include "string.h"int num[31],dp[3001000];int main(){ int n,a,m,b,c,k,ok,i,j; double x,q,sum; char ch,str[101]; while (scanf("%lf%原创 2014-04-23 14:32:55 · 508 阅读 · 0 评论 -
HDU 4283 区间DP
#include "stdio.h"#include "string.h"#define inf 2000000000;int min(int a,int b){ if (a<b) return a; else return b;}int main(){ int ii,t,n,i,j,k,s,e; int dp[101][101],a[101],sum[10原创 2014-05-16 16:43:01 · 532 阅读 · 0 评论 -
HDU 1513 最长公共子序列拓展DP
将原字符串倒置,然后与原字符串求最长公共子序列, ans=n-dp[n][n]。原创 2014-04-26 15:47:00 · 590 阅读 · 0 评论 -
HDU 1428 最短路+记忆化搜索
他考虑从A区域到B区域仅当存在一条从B到机房的路线比任何一条从A到机房的路线更近(否则可能永远都到不了机房了…”这句话一定要理解清楚。就是说,对于当前位置,如果下一个状态与终点的最短距离大于或者等于当前位置到终点的最短距离,那么这个下一个状态是不可取的!到此,就能明白,此题就是求出所有点与终点的最短距离,然后再从起点进行记忆化搜索。#include "queue"#include原创 2014-04-26 14:43:51 · 616 阅读 · 0 评论 -
HDU 1559 最大子矩阵
对数据进行压缩 然后枚举每个矩形即可#include "stdio.h"#include "string.h"#include "math.h"int a[1001][1001];int main(){ int ans,count,k,t,n,m,x,y,i,j; scanf("%d",&t); while (t--) { scanf("%d%d%d%d",&n,&原创 2014-04-26 15:05:16 · 483 阅读 · 0 评论 -
HDU 2476 区间DP
先是考虑将所有与目标字符串不相同的刷成目标串:dp[i][j]表示刷i-j区间,初始条件:dp[i][j]=dp[i+1][j]+1;对于k=(i+1...j )如果str[k]==str[i],则dp[i][j]=min(dp[i][j],dp[i+1][k]+dp[k+1][j]),,因为刷i的时候可以与k同时刷。上面是对初始串与目标串完原创 2014-05-18 17:44:51 · 476 阅读 · 0 评论 -
HDU 1208 DP || 记忆化搜索
DP:#include "stdio.h"#include "string.h"int main(){ int i,j,n; char ch; __int64 dp[101][101],a[101][101]; while (scanf("%d",&n)!=EOF) { if (n==-1) break; for (原创 2014-05-19 13:51:30 · 553 阅读 · 0 评论 -
HDU DP 简单题
横竖分别求一下 最大不连续字段和即可#include "stdio.h"#include "string.h"int dp[200001];struct comp{ int no,yes;}b[2];int Max(int a,int b){ if (a<b) return b; else return a;}int main(){ int原创 2014-05-13 11:04:12 · 592 阅读 · 0 评论 -
HDU 1502 DP+大数
转移方程 ans[n][n][n]=ans[n-1][n][n]+ans[n][n-1][n]+ans[n][n][n-1];原创 2014-04-27 09:54:46 · 466 阅读 · 0 评论 -
HDU 1494 DP
dp方程: dp[i][j]=max( dp[i-1][j-1],dp[i-1][j+5]); i=原创 2014-04-28 09:12:30 · 475 阅读 · 0 评论 -
HDU 1508 DP || 记忆化搜索
DP:#include "stdio.h"#include "string.h"__int64 dp[100010],a[100010];char str[100010];int main(){ int n,i; while (gets(str)) { if (str[0]=='0') break; n=strlen(str原创 2014-05-19 16:21:05 · 568 阅读 · 0 评论 -
HDU 1466 DP
n条直线互不平行且无三线共点的最多交点数max=1+2+……(n-1)=n(n-1)/2,所以n=20的话,最大的交点数是190本题是求有多少种交点数:容易列举出N=1,2,3的情况:00,10,2,3如果已知的情况,我们来分析加入第N条直线的情况(这里N=4):1、第四条与其余直线全部平行 => 无交点;2、第四条与其中两条原创 2014-04-28 13:54:17 · 459 阅读 · 0 评论 -
HDU 1421 DP
先qsortdp[i][j]=min(dp[i-2][j-1]+(a[i]-a[i-1])*(a[i]-a[i-1]),dp[i-1][j]);原创 2014-04-28 14:41:10 · 484 阅读 · 0 评论 -
HDU 2577 DP || 贪心
DP:#include "stdio.h"#include "string.h"int Min(int a,int b){ if (a<b) return a; else return b;}int main(){ int n,i,le; int a[1001],b[1001]; char str[1001]; while(scan原创 2014-05-13 09:49:00 · 569 阅读 · 0 评论 -
POJ 1661 记忆化搜索
测试数据:103 8 17 200 10 80 10 134 14 3原创 2014-05-20 15:18:26 · 524 阅读 · 1 评论 -
POJ 2955 区间DP
求最多能匹配的括号数*2原创 2014-05-20 15:48:50 · 460 阅读 · 0 评论 -
HDU 1331 poj 1579记忆化搜索
记忆化搜索 水#include "stdio.h"#include "string.h"int dp[21][21][21];int dfs(int a,int b,int c){ if (dp[a][b][c]) return dp[a][b][c]; if (a<=0 || b<=0 || c<=0) return 1; if (a<b && b<c) return原创 2014-04-23 10:50:30 · 504 阅读 · 0 评论 -
HDU 3182 状压DP
每个汉堡有价值a,和消耗b,原创 2014-05-14 10:04:39 · 581 阅读 · 0 评论 -
HDU 1505 DP 最大完全子矩阵
对矩阵进行压缩 然后爆搜即可勉强分到DP里吧原创 2014-04-26 16:29:54 · 448 阅读 · 0 评论 -
HDU 2870 DP 最大完全子矩阵
HDU 1505 升级版枚举a,b,c 各做一遍最大完全子矩阵原创 2014-05-21 10:18:57 · 512 阅读 · 0 评论 -
HDU 2159 完全背包模板题
#include "stdio.h"#include "string.h"int max(int a,int b){ if (a<b) return b; else return a;}int main(){ int n,m,k,s,i,j,l,ans; int hash[101][101]; int a[101],b[101]; while (原创 2014-05-20 19:43:24 · 722 阅读 · 0 评论 -
HDU4571 记忆化搜索
n个城市,m条路,总时间t,起始城市s,终点城市e接下来给出各个城市的浏览时间,各个城市浏览后的满意程度。然后是m条路的信息。要求一个浏览顺序,使得总的满意程度最大,然后经过一个城市可以选择不去浏览,当前浏览城市的满意度一定要比前一个浏览城市的满意度高,并且最终要回到城市e。原创 2014-07-16 10:16:46 · 533 阅读 · 0 评论 -
POJ 1088 DP || 记忆化搜索
按高度从小到大排序一遍原创 2014-05-20 16:56:22 · 483 阅读 · 0 评论 -
POJ 2817 状压DP&&记忆化搜索
这个题的意思是第一行给出case数N (1 要求的是,按任意顺序排列这些单词,可以在单词前面加任意个空格,使得相邻的单词上下对应的字母数目最多,并输出最多是多少。先预处理出每两个单词相连所能原创 2014-07-19 10:00:19 · 473 阅读 · 0 评论 -
HDU 4856 DP
2014 Multi-University Training Contest 1原创 2014-07-23 14:23:03 · 474 阅读 · 0 评论 -
POJ 2533 LIS模板
n*log(n) 模板#include "stdio.h"#include "string.h"#include "math.h"int sum;int a[1010],dp[1010];void updata(int x){ int l,r,mid; l=1;r=sum; while (l<=r) { mid=(l+r)原创 2014-07-25 14:01:21 · 470 阅读 · 0 评论 -
POJ 1836 LIS拓展
令到原队列的最少士兵出列后,使得新队列任意一个士兵都能看到左边或者右边的无穷远处。输出最少出队人数。计算一下每个点的原创 2014-07-25 14:54:13 · 491 阅读 · 0 评论 -
POJ 1276 背包
各种不同面值的货币,每种面值的货币有不同的数量,请找出利用这些货币可以凑成的最接近且小于等于给定的数字cash的金额。原创 2014-07-25 10:24:29 · 454 阅读 · 0 评论 -
POJ 3254 状压DP
一个n*m的矩阵,每个格子是0或者1,1表示土壤肥沃可以种植草地,0则不可以。在种草地的格子可以放牛,但边相邻的两个格子不允许同时放牛,问总共有多少种放牛的方法?(不放牛也算一种情况)状压DP ,原创 2014-07-28 10:10:36 · 464 阅读 · 0 评论 -
POJ 1185 状压DP
同HDU 4539 改成滚动数组再写一遍原创 2014-07-27 15:54:24 · 485 阅读 · 0 评论