摘要: /*先按l排序 再每次找出一段最长的递增序列!*/#include <stdio.h>#include <stdlib.h>#include <string.h>struct stick{ int l, w;}st[50010];bool used[50010];int cmp(const void *a, const void *b){ stick *s1 = (stick*)a, *s2 = (stick*)b; if(s1 -> l == s2 -> l) return s1 -> w - s2 -> w; return s1 阅读全文
posted @ 2011-04-09 03:13 L.. 阅读(148) 评论(0) 推荐(0) 编辑
摘要: /*抄书上的程序..用c语言写的老是WA每次选效益最高的交换*/#include <iostream>#include <fstream>#include <vector>#include <algorithm>using namespace std;struct Mouse{ double j,f; double shouyi;};bool comp(const Mouse &d1,const Mouse &d2){ if(d1.shouyi != d2.shouyi) return d2.shouyi < d1.shou 阅读全文
posted @ 2011-04-09 03:09 L.. 阅读(191) 评论(0) 推荐(0) 编辑
摘要: /*转化为数塔问题dp[i][j] i 表示第i秒 j表示第j个位置 能够拿到的最大馅饼数状态转移方程dp[i][j] = max{dp[i+1][j-1],dp[i+1][j],dp[i+1][j+1]} + a[i][j]; 时刻注意边界*/#include <stdio.h>#include <string.h>const int MAX = 100001; int dp[MAX][11]; //1 ~ 100000秒int max2(int d1,int d2){ return d1 > d2 ? d1 : d2;}int max3(int d1,int 阅读全文
posted @ 2011-04-09 02:59 L.. 阅读(229) 评论(0) 推荐(0) 编辑
摘要: /*经典的动态规划*/#include <iostream>using namespace std;char str1[1000];char str2[1000];int dp[1001][1001];int main(){ while(cin >> str1 >> str2){ int len1 = strlen(str1); int len2 = strlen(str2); int max = -1; memset(dp,0,sizeof(dp)); for(int i = 0; i < len1; i++){ for(int j = 0; j & 阅读全文
posted @ 2011-04-09 02:22 L.. 阅读(154) 评论(0) 推荐(0) 编辑
摘要: /*若N个数 为递增序列则最多需要N个导弹系统贪心 + DP 见注释*/#include <stdio.h>#define MAX 100000int height[MAX]; //height[i]表示第i个防导弹系统所能防御的最大高度int t; //t个数int high; //height[i]中 最高高度 的 下标int a[MAX];int main(){ int i,j; //j 导弹系统个数 while(scanf("%d",&t)!= EOF){ scanf("%d",&a[0]); height[0] = 阅读全文
posted @ 2011-04-09 02:17 L.. 阅读(348) 评论(0) 推荐(0) 编辑
摘要: /*给定K个整数的序列{ N1, N2, ..., NK },其任意连续子序列可表示为{ Ni, Ni+1, ...,Nj },其中 1 <= i <= j <= K。最大连续子序列是所有连续子序列中元素和最大的一个,例如给定序列{ -2, 11, -4, 13, -5, -2 },其最大连续子序列为{ 11, -4, 13 },最大和为20 状态转移方程 dp[i] = max(dp[i - 1] + a[i],a[i]) 最长公共子序列 求出最长的起点 和 终点*/#include <stdio.h>int main(){ int i,start,end,ma 阅读全文
posted @ 2011-04-09 02:09 L.. 阅读(337) 评论(0) 推荐(0) 编辑
摘要: 还得好好理解一下...为什么注释部分去掉 不能AC ? 知道的麻烦指导一下!#include <stdio.h>#define L(x) ((x) << 1)#define R(x) ((x) << 1 | 1)const int MAXN = 200000;struct SegTree{ int l,r; int metal; int value; bool lazy; int getMid(){ return ( l + r ) >> 1; } int getDis(){ return (r - l + 1); }}tree[MAXN < 阅读全文
posted @ 2011-04-09 01:12 L.. 阅读(184) 评论(0) 推荐(0) 编辑