
简单动态规划
文章平均质量分 51
acmdream
我是福建某高校2013级在校生,学业之余喜欢研究算法。
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
HDU 1003(最大子序列和)
题意:给出数据组数,每组第一个数为序列的长度n,后面跟着n个数。求这个序列的最大子序列和。#include #include void res(){ int n, sum = 0, _max = INT_MIN, t, head = 0, s, e; scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf(原创 2014-01-11 13:09:42 · 710 阅读 · 0 评论 -
HDU 1176(时间dp)
题意:如题。#includeusing namespace std;int p[100000+10][11],dp[100000+10][11];int max(int a,int b,int c){ int d; d=a>b ? a : b; return d > c ? d : c;}int max(int a,int b)原创 2014-01-15 15:38:40 · 574 阅读 · 0 评论 -
HDU 1231(最大连续子序列)
题意:如题。 #include int main(){ int n, sum, ans, st, ed, x, y, a[10005]; while(scanf("%d", &n), n) { for(int i = 0; i < n; i++) scanf("%d", &a[i]);原创 2014-01-15 20:49:25 · 655 阅读 · 0 评论 -
HDU 1159(最长公共子序列)
题意:给出两个字符串,求最长公共子序列。 #include #include #include #include #include using namespace std;#define MAX(a, b) ((a) > (b) ? (a) : (b))int main(){ string a, b; int i, j;原创 2014-01-14 22:28:40 · 514 阅读 · 0 评论 -
HDU 1160(类似于最长上升子序列)
题意:给出一连串老鼠的体重和速度,求最长的序列符合老鼠体重是严格递增,而速度是严格递减。 #include #include #include using namespace std;#define MAX(a, b) ((a) > (b) ? (a) : (b))struct Mice{ int weight, speed, mark;原创 2014-01-14 22:43:19 · 727 阅读 · 0 评论 -
HDU 1133(卡特兰数;动态规划)
题意:M+N个人排队买票,票的单价是50¥,每个人只能买一张。 M个人拿50的去买,N个人拿100的去买,然后悲剧的是售票处开始的时候没有钱,所以如果拿100块买票人前面的拿50块买票的人小于或者等于用100块买票的人,这种排队方式就不合法,也就是不能顺利全部都买到票(因为没零钱找了)!题目分析:这是一个Catalan数的非常经典的应用,买票问题,首先我们用"0"表示用50块买票的人,用“原创 2014-01-14 16:59:15 · 1034 阅读 · 0 评论 -
HDU 1087(最长上升子序列)
题意:求最长上升子序列的和。 #include #include int T[1009];__int64 sum[1009];#define MAX(a, b) ((a) > (b) ? (a) : (b))int main(){ int n, i, j; while (scanf("%d", &n) != EOF && n) {原创 2014-01-13 13:26:03 · 515 阅读 · 0 评论 -
HDU 1081(经典动归,求最大子矩阵)
题意:给你一个矩阵,求最大子矩阵。。 #include #include #include int array[109][109];int dp[109];int sum[109];#define MAX(a, b) ((a) > (b) ? (a) : (b))int main(){ int n, i, j, k, _max, t;原创 2014-01-13 12:21:42 · 617 阅读 · 0 评论 -
HDU 1069(最长下降子序列)
题意:给n种类型的箱子,每种类型提供无限的数量。要求把这些箱子尽量叠高,上一层箱子的长宽必须都比下一层的箱子小,求可以叠的最高高度。 #include #include #include using namespace std;#define MAXN 120#define MAX(a, b) ((a) > (b) ? (a) : (b))#define M原创 2014-01-12 23:40:06 · 751 阅读 · 0 评论 -
HDU 1058(DP)
题意:如题。 #include #include int result[5845];#define MIN(a, b) ((a) > (b) ? (b) : (a))void calc(char* s, int n){ int a = n % 10, b = n / 10 % 10; if (b == 1 || a > 3 || a == 0原创 2014-01-12 22:29:45 · 473 阅读 · 0 评论 -
HDU 1024(动态规划+滚动数组+决策优化,求m个不相交字段和最大值)
题意:求的是给定n个数,求m个不相交的子段和的最大值.dp[i][j]=max(dp[i][j-1]+a[j],max(dp[i-1][t])+a[j]);(i代码写成f[j]=max(f[j-1],best[cur][j-1])+a[j]; //对应于下面的第一点best[1-cur][j]=max(f[j],best[1-cur][j-1]);//第二点dp[i][j]表示是前原创 2014-01-12 10:53:16 · 769 阅读 · 0 评论 -
HDU 1257(贪心;动态规划(最长上升子序列))
题意:如题。 这道题目可以用贪心和动态规划求解,其实两种方法都是想通的。 贪心思想:对于每个飞来的导弹,查找能够打到它的,飞得最低的防御系统,如果没有,则加入一个新防御系统。动态规划思想:就是求最长上升子序列。贪心方法:#include using namespace std;int dp[100000],num[100000],heigh[100000];原创 2014-01-16 11:44:28 · 764 阅读 · 0 评论