1、完全背包--背包不允许剩余#include #include #define N 50002#define M 2002using namespace std; //测试OJ:nyoj 311 /* 背包不允许剩余,与允许剩余相比,只需将d[i]初始为负无穷大,d[0]=0 d[i]...
分类:
其他好文 时间:
2014-11-28 22:35:05
阅读次数:
275
#include #include #include #define N 1002
using namespace std; int f[N];
bool d[N][N];
/* 如果(i,j)回文(i>t; while(t--) { string s; cin>>s; n=s.length(); ...
分类:
其他好文 时间:
2014-11-28 21:26:20
阅读次数:
234
动态规划二位数组 1 class Solution { 2 public: 3 int uniquePaths(int m, int n) { 4 //c[i][j] = c[i-1][j] + c[i][j-1]; 5 if(m==0 || n==0) 6 ...
分类:
其他好文 时间:
2014-11-28 20:06:50
阅读次数:
177
题目描述:
Create a class called Football. In football, scores are incremented by either
2, 3, or 7 points. Given a numerical input (integer between 1 and 75)
representing a final score, calculate the n...
分类:
其他好文 时间:
2014-11-28 18:21:33
阅读次数:
276
简单的动态规划题,一维数组就够了。递推公式是c[n] = c[n-1] + c[n-2],c[n]表示楼梯数为n时的上楼方法。ps:第一提交时由于没有释放new的int空间,所以报了一个runtime error。 1 class Solution { 2 public: 3 int cli...
分类:
其他好文 时间:
2014-11-28 18:08:06
阅读次数:
192
一、最长递增序列的问题描述:
求一个整数序列的最长递增子序列,子序列不要求是连续的。例如:
Input:4,6,9,6,7,6,3,8,10;Output:5
二、解决方法:
1、用动态规划的方法解决。从问题我们可以知道,我们最终得到的最长递增子序列,其任意一段子序列也是对应序列中的最长子序列。这样说可能不好理解,就以上面的例子来说:
最长子序列为:4,6, 7, 8...
分类:
编程语言 时间:
2014-11-27 16:31:30
阅读次数:
209
多种方法,我用DP做的。
我当成的 最长下降子序列做的。 问了下其他人,有树形DP的,有差分约束用最短路的。
还有当作 二维的背包问题的。
最长单调子序列,长宽高 x,y,z 分别枚举成六个。然后排序,找最长单调子序列即可。
#include
#include
#include
#include
#include
#include
#include
#include
#include
...
分类:
其他好文 时间:
2014-11-27 10:48:57
阅读次数:
228
动态规划:There areNchildren standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following ...
分类:
其他好文 时间:
2014-11-26 23:58:18
阅读次数:
235
错误的转移方程
dp[i][j] 把i当作了步数,以为至多走N步就可以了。作死啊
#include
#include
#include
#include
#define maxn 1100
#define inf 0x3f3f3f3f
const double eps=1e-8;
using namespace std;
int dp[12][1<<12];
int maps[12][12];...
分类:
其他好文 时间:
2014-11-26 21:03:10
阅读次数:
359
#include
#include
#include
#include
#include
using namespace std;
/*
*最长公共子序列(动态规划)
*/
vector> c;//c[i][j]记录串a[0..i]与串b[0..j]之间的最长公共子序列的长度
vector> b;//b[i][j]记录c[i][j]的值是由哪一个子问题的解得到的
void LCSLength(...
分类:
其他好文 时间:
2014-11-26 20:57:44
阅读次数:
199