
动态规划
文章平均质量分 80
u010660276
这个作者很懒,什么都没留下…
展开
-
dp--upc2447
2447: 吃饭Time Limit: 1 Sec Memory Limit:64 MBSubmit: 10 Solved: 4[Submit][Status][Web Board]Description桐桐放学了,在学校食堂吃起了饭….这里的饭十分好吃,但是桐桐的钱有限且肚子空间有限(^_^),虽然每种饭有无限多,但他只能吃部分,且每一种饭可增加一定的能量。桐原创 2013-08-19 19:20:56 · 1097 阅读 · 1 评论 -
01背包-poj3628
典型的01背包。题意:告诉你所有牛的高度和棚的高度,问最小差多少。刚开始看错题了,wa了好多遍,我以为是牛的高度不能超过b,可原题是说超过的最小高度,悲催了。#include#include#includeusing namespace std;long long high[25];long long f[1000050];int main(){ int n;原创 2013-08-04 20:58:54 · 638 阅读 · 0 评论 -
最长上升子序列
O(n^2)算法:#include#includeusing namespace std;int dp[10];int main(){ int a[10]; int n; cin>>n; for(int i=1;i<=n;i++) cin>>a[i]; memset(dp,0,sizeof(dp)); dp[1]=1;原创 2013-09-06 10:16:37 · 592 阅读 · 0 评论 -
二维费用背包--poj1948
Language:DefaultTriangular PasturesTime Limit: 1000MS Memory Limit: 30000KTotal Submissions: 5789 Accepted: 1855DescriptionLike everyone, cows enjoy varie原创 2013-09-05 20:36:34 · 811 阅读 · 0 评论 -
混合背包--poj3260
Language:DefaultThe Fewest CoinsTime Limit: 2000MS Memory Limit: 65536KTotal Submissions: 4208 Accepted: 1251DescriptionFarmer John has gone to town to buy so原创 2013-09-05 17:34:16 · 619 阅读 · 0 评论 -
多重背包变形--poj2392
Language:DefaultSpace ElevatorTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 7307 Accepted: 3429DescriptionThe cows are going to space! They pl原创 2013-09-05 15:48:32 · 726 阅读 · 0 评论 -
多重背包--poj1014
Language:DefaultDividingTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 53204 Accepted: 13555DescriptionMarsha and Bill own a collection of marb原创 2013-08-20 12:44:03 · 686 阅读 · 0 评论 -
多重背包(模板)--hdoj2191
前几天遇到过多重背包,不太会,没做,今天又遇到了,有必要学一下一种好想好写的基本方法是转化为01背包求解:把第i种物品换成n[i]件01背包中的物品,则得到了物品数为Σn[i]的01背包问题,直接求解,复杂度仍然是O(V*Σn[i])。但是我们期望将它转化为01背包问题之后能够像完全背包一样降低复杂度。仍然考虑二进制的思想,我们考虑把第i种物品换成若干件物品,使得原问题中第i种物品可取原创 2013-08-13 18:38:11 · 645 阅读 · 0 评论 -
01背包-poj1976(不好想)
刚开始看了半天题目,没太看明白,但看看样例你就知道什么意思了。自己没想到用01背包怎么做,于是看了人家的代码,是把连续的k节车厢的人加起来,然后多加起来的数组背包,由于刚开始做dp,感觉自己形不成dp的思路,很混乱。想把它改成一位数组的,但不太会改,还需努力努力啊!#include#include#include#includeusing namespace std;int tr原创 2013-08-04 17:30:32 · 696 阅读 · 0 评论 -
二维费用背包(不错)--poj2576
Language:DefaultTug of WarTime Limit: 3000MS Memory Limit: 65536KTotal Submissions: 8023 Accepted: 2153DescriptionA tug of war is to be arranged at the lo原创 2013-09-05 21:51:21 · 1141 阅读 · 0 评论 -
多重背包变形--poj1742
Language:DefaultCoinsTime Limit: 3000MS Memory Limit: 30000KTotal Submissions: 25858 Accepted: 8750DescriptionPeople in Silverland use coins.They have coi原创 2013-09-05 13:38:03 · 710 阅读 · 0 评论 -
最长公共子序列
upc2431(裸的最长公共子序列)#include#includeusing namespace std;int c[1010][1010];int main(){ string a,b; cin>>a>>b; int n=a.size(),m=b.size(); for(int i=1; i<=n; i++) c[i][0]=0;原创 2013-09-06 10:27:53 · 560 阅读 · 0 评论 -
最大连续和(hdu1003)
状态转移方程:d[i]=max(0,d[i-1])+a[i].#includeusing namespace std;int N[100005];int main(){ int t,n,s; int i,k,sum,maxa; int flag1,flag2; cin>>t; for(k=1; k<=t; k++) { s原创 2013-09-06 10:32:41 · 610 阅读 · 0 评论 -
最长公共子序列--UVa10635
Problem DPrince and PrincessInput: Standard InputOutput: Standard OutputTime Limit: 3 SecondsIn an n x n chessboard, Prince and Princess plays a game. The squares in the chessboard are n原创 2013-09-07 10:25:51 · 721 阅读 · 0 评论 -
动态规划--UVa10891
题意:有一个长度为n的序列,a,b轮流从两边取数,a先取,可以一次取多个,但要是同一边,得分为所取数值和,问在a,b都采取最优策略下,a得分减去b的结果。状态转移:d[i,j]=sum[i.j]-min{d[i+1,j],d[i+2,j]......d[i,j-1],d[i,j-2]......0}d[i,j]表示地i~j中,根据提议的取法,先取的得分的最大值。#includeusi原创 2013-09-07 15:01:37 · 779 阅读 · 0 评论 -
分组背包--hdu1712
Online JudgeOnline ExerciseOnline TeachingOnline ContestsExercise AuthorF.A.QHand In HandOnline AcmersForum | DiscussStatistical ChartsProblem ArchiveRealtime Judge Statu原创 2013-09-06 22:19:34 · 716 阅读 · 0 评论 -
状态压缩dp--UVa11825
刚开始刷dp,看了好久才看明白是怎么回事。首先是题意:有N台电脑,每台电脑有N(N思路:看书上的,把n个集合p1,p2...分成尽量多组,是得每组中所有集合的并集等于全集。代码如下:#include#include#includeusing namespace std;const int maxn=1<<16;//p[i]表示计算机i相连的机器的集合,cover[s]原创 2013-09-08 10:30:25 · 562 阅读 · 0 评论 -
状态压缩dp--poj2686
Language:DefaultTraveling by StagecoachTime Limit: 2000MS Memory Limit: 65536KTotal Submissions: 1634 Accepted: 486 Special JudgeDescriptionOnce upon原创 2013-09-10 09:17:50 · 824 阅读 · 0 评论 -
最长公共子序列-uva10405
这个题含有空格,被坑了。简单的最长公共子序列。下面是代码:#include#include#include#include#includeusing namespace std;int c[1010][1010];int main(){ //freopen("in.txt","r",stdin); string a,b; while(getl原创 2013-09-13 22:25:26 · 704 阅读 · 0 评论 -
DAG上的最短路--uva103
瞬间感觉自己的c++实践还真是不够啊,长知识了!题意:有k个盒子,每个盒子有n维,问最多能嵌套多少。#include#include#include#include#includeusing namespace std;int k,n;struct Box{ int id; vector a; bool operator<=(const Box原创 2013-09-17 09:52:15 · 810 阅读 · 0 评论 -
最长公共子序列uva--111
这个题的输入刚开始没看明白,ci代表事件c发生的顺序是i,所以最后相当于是是对i求最长公共子序列。#include#include#includeusing namespace std;int cor[25],stu[25];int c[25][25];int main(){ //freopen("in.txt","r",stdin); int n;原创 2013-09-15 10:39:08 · 551 阅读 · 0 评论 -
数塔--poj3176
水题不多说。#include#include#include#include#include#include#include#include#include#include#includetypedef long long LL;using namespace std;int cow[355][355];int main(){ //freopen("i原创 2013-10-03 14:17:50 · 645 阅读 · 0 评论 -
dp-poj2229
Language:DefaultSumsetsTime Limit: 2000MS Memory Limit: 200000KTotal Submissions: 11154 Accepted: 4479DescriptionFarmer John commanded his cows to search原创 2013-10-03 15:22:06 · 617 阅读 · 0 评论 -
动态规划--uva674
Coin Change Suppose there are 5 types of coins: 50-cent, 25-cent, 10-cent, 5-cent, and 1-cent. We want to make changes with these coins for a given amount of money.For example, if we h原创 2013-09-19 11:26:22 · 735 阅读 · 0 评论 -
矩阵链乘
转自:http://blog.youkuaiyun.com/liguisen/article/details/2158127以下内容参考(摘抄)《算法设计与分析》,王晓东编著,清华大学出版社2003年1月第1版。给定n个矩阵{A1,A2,…,An},其中Ai与Ai+1是可乘的,i=1,2,…,n-1。考察这n个矩阵的连乘积A1A2…An。由于矩阵乘法满足结合律,故计算矩阵的连乘积可以有许多不同的计转载 2013-09-06 11:04:23 · 722 阅读 · 0 评论 -
矩阵链乘--uva10003
长知识了。这个题类似于矩阵链乘,记忆化解决,要注意输出格式有一个“.”。dp[i][j]表示在第i个坐标与第j个坐标之间的最小费用。#include#include#include#includeusing namespace std;const int INF=10000000;int a[55];int dp[55][55];int len,n;int DP(原创 2013-09-19 14:39:11 · 734 阅读 · 0 评论 -
dp--uva116
又是超时啊。# include # define MIN(X,Y) ((X)<(Y) ? (X):(Y))int f[12][105];int p[12][105];int col, row;int main(){ int i, j, ans, t, x; while (~scanf("%d%d", &row, &col)) {原创 2013-09-21 16:20:34 · 581 阅读 · 0 评论 -
dp
Problem Description话说在qtech有一个ACM集训室,它就在主教学楼A423,Qtech的ACMer平时就是聚在这个教室里面刷题。这个教室里面鱼龙混杂,有大一的、大二的、大三的,当然还有大四的(比如我这个菜鸟)。我们遇到问题就会相互讨论,集训室里的学习氛围非常浓厚,当然我们偶尔也会放松一下,锻炼一下身体,比如。。。。打乒乓球!我们自己创造了一种乒乓球的新玩法,下面就让我介绍原创 2013-11-19 13:03:54 · 814 阅读 · 0 评论 -
简单dp
Language:DefaultApple CatchingTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 6687 Accepted: 3253DescriptionIt is a little known fact that cows原创 2013-11-19 15:27:15 · 854 阅读 · 0 评论 -
区间DP【poj3280】
Language:DefaultCheapest PalindromeTime Limit: 2000MS Memory Limit: 65536KTotal Submissions: 5031 Accepted: 2451DescriptionKeeping track of all the cows c原创 2013-12-29 21:55:39 · 532 阅读 · 0 评论 -
状态压缩DP+poj2441
题意:有n头牛,m个房间,每头牛有不同的喜欢的房间,把他们安排好,一共有多少种方法思路:dp[i]表示当前状态一共有多少种方法往下递推。#include#include#includeusing namespace std;int N,M;int dp[(1<<20)+5],map[25][25];int main(){ #ifndef ONLINE_JUDGE原创 2014-01-13 22:44:37 · 883 阅读 · 0 评论 -
Codeforces Round #214 (Div. 2)(背包变形)
A. Dima and Guards只需要比较一下,守卫的最小要求的和与给定值的大小即可#include#includeusing namespace std;int n,x1,y1,x2,y2;int who,choc,juice;bool can(int x,int y){ return x+y<=n;}int main(){ cin>>n;原创 2014-01-14 17:01:23 · 699 阅读 · 0 评论 -
SD五一联赛(加权并查集)
ArnyTime Limit: 3000MS Memory limit: 65536K题目描述Bad working coordinator was the everlasting trouble of their spaceship. Arny already had been working under this trouble while his not ve原创 2014-05-01 15:50:32 · 824 阅读 · 0 评论 -
强连通分量+dp+uva11324
思路:先找出强连通分量,缩点,重建图,然后dp求最大节点个数#include#include#include#include#includeusing namespace std;const int maxn=1010;vector G[maxn];stack S;int pre[maxn],sccno[maxn],lowlink[maxn],dfs_clock,scc_cn原创 2014-03-21 16:03:41 · 469 阅读 · 0 评论 -
Codeforces Round #240 (Div. 2)(D:dp递推)
A - Mashmokh and Lights原创 2014-04-07 14:14:31 · 529 阅读 · 0 评论 -
数位dp
sgx和路飞原创 2014-06-18 22:07:17 · 446 阅读 · 0 评论 -
Codeforces Round #247 (Div. 2)
C. k-TreeQuite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called ak-tree.A k-tree is an in原创 2014-06-20 14:53:59 · 575 阅读 · 0 评论 -
AC自动机+DP+大数poj1625
Language:DefaultCensored!Time Limit: 5000MS Memory Limit: 10000KTotal Submissions: 8102 Accepted: 2191DescriptionThe alphabet of Freeland consists of exac原创 2014-09-04 22:29:56 · 641 阅读 · 0 评论 -
AC自动机+DP(总结)+hdu2457
Online JudgeOnline ExerciseOnline TeachingOnline ContestsExercise AuthorF.A.QHand In HandOnline AcmersForum | DiscussStatistical ChartsProblem ArchiveRealtime Judge Statu原创 2014-09-05 11:39:48 · 567 阅读 · 0 评论 -
AC自动机+DP+hdu2296
Online JudgeOnline ExerciseOnline TeachingOnline ContestsExercise AuthorF.A.QHand In HandOnline AcmersForum | DiscussStatistical ChartsProblem ArchiveRealtime Judge Statu原创 2014-09-06 09:46:28 · 410 阅读 · 0 评论