- 博客(13)
- 收藏
- 关注
原创 poj2342-Anniversary party(树形动规)
#include #include #include using namespace std;struct poj2342 { /*[问题描述]:大学聚会,要求到场的任何两个人都不是上司/下属关系,每个人都有一个高兴值c[i],可正可负, 要求让总的高兴值最大*/ /*[解题思路]:f[i][0]表示以i为根的子树的最大高兴值且第i个人不去,f[i][1]表示以i为根的子树的最大高
2017-04-17 22:22:12
372
原创 poj1160-Post Office(区间动规+四边形不等式优化)
#include #include #include using namespace std;int n, m;int x[305];int f[35][305], p[400][305];int w[305][305];int Left[305][305], Right[305][305];//left[i][j]表示第i+1,i+2,...,j个村庄到第i个村庄的距离和
2017-04-17 22:20:30
411
原创 poj2533-Longest Ordered Subsequence(最长上升子序列)
#include #include #include using namespace std;struct poj2533 { /*[问题描述]:求最长上升子序列的长度*/ /*[解题思路]:f[i]表示以i结尾的最长上升子序列的长度,则f[i]=max{f[j]|v[j]<v[i],j<i}+1*/ int n; int v[1005]; int f[1005]; voi
2017-04-11 19:39:57
371
原创 poj1159-Palindrome(最长公共子序列)
#include #include #include using namespace std;struct poj1159 { /*[问题描述]:已知一个序列,求至少添加多少个元素使得该序列成为一个回文序列*/ /*[解题思路]:需要添加的元素数=原序列长度-原序列与逆序列的最长公共子序列长度, *从而将问题转换为最长公共子序列问题. *由于每次f[i][j]的决策只需要考虑f[
2017-04-11 19:19:13
407
原创 poj1458-Common Subsequence(最长公共子序列)
#include #include #include using namespace std;char str1[1050], str2[1050];int f[1050][1050];struct poj1458 { /*[问题描述]:求连个序列的最长公共子序列的长度*/ /*[解题思路]:f[i][j]表示序列str1[1,...i]与序列str2[1,...j]的最长公共子
2017-04-11 18:48:34
452
原创 poj1050-To the Max(最大子段和)
#include #include #include using namespace std;int s[105][105][105];int f[105];int t[105][105];int A[105][105];struct poj1050 { /*[问题描述]:用矩阵内部的所有元素和来衡量一个矩阵的大小,求最大子矩阵的元素和*/ /*[解题思路]:令s[i][j]
2017-04-11 16:53:10
408
原创 poj2593-Max Sequence(最大子段和)
#include #include #include using namespace std;int num[100005];int f[100005];int g[100005];int h[100005];struct poj2593 { /*[问题描述]:找出两个子段使得它们的和最大*/ /*[解题思路]:f[i]表示以第i个数结尾的最大子段和 * g[i]表示以第
2017-04-11 15:53:49
365
原创 poj2576-Tug of War(二维背包)
#include #include #include using namespace std;bool f[45010][110];int w[110];struct poj2576 { /* [问题描述]:n个人,体重分别为w[1],w[2],...,w[n] * 将n个人分为两组,人数只差不得大于1 * 要求两组的体重和最接近 */ /* [解题思路]:f[n][i]
2017-04-11 14:50:35
614
原创 poj1976-A Mini Locomotive(01背包)
#include #include #include using namespace std;int t, n, M;int v[50005];int s[50005];int f[50005][4];struct poj1976 { /*【问题描述】:有n节车厢,每节车厢有v[i]个乘客,有3列火车, * 每列火车只能拉连续的M节车厢,求最多能拉多少乘客 */ /
2017-04-02 17:14:08
418
原创 poj1745-Divisibility(01背包)
#include #include #include using namespace std;int n, K;int v[10005];bool f[10005][105];struct poj1745 { /*【问题描述】:有n个数{v1,v2,...,vn},以及一个数K, * 在这N个数之间添加+或-得到一个表达式,判断该表达式的值能否被K整除 */ /*【解题思
2017-04-02 15:13:47
357
原创 poj3628-Bookshelf2(01背包)
#include #include #include using namespace std;int n, B, S = 0;int h[25];bool f[20000005];struct poj3628 { /*【问题描述】:有n头奶牛,每头奶牛i有身高h[i],有一个高为B的书架, * 要求选出奶牛的一个子集J,使得sum{h[i]}-B最小且sum{h[i]}-B>
2017-04-02 14:11:45
656
原创 poj3624-Charm Bracelet(01背包模板题)
#include #include #include using namespace std;struct poj3624 { /* 【问题描述】:典型的01背包问题, * 给定n个物品,每个物品i有重量w[i]和价值d[i],背包容量为M, * 要求在不超过背包容量的前提下,使背包中物品的价值最大(每个物品只能出现一次) */ /* 【解题思路】:f[n,v]表示只考虑
2017-04-02 13:22:03
619
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人