上一页 1 ··· 43 44 45 46 47 48 49 50 51 ··· 66 下一页
摘要: 先粘上TLE的代码,先对高度离散化,然后DP高度求解。复杂度过高。代码如下:View Code #include <cstdlib>#include <cstdio>#include <cstring>#include <map>#include <iostream>#include <algorithm>#define MAXN 100005using namespace std; int N, cnt;int seq[MAXN], cseq[MAXN];long long dp[MAXN]; map<int,in 阅读全文
posted @ 2012-04-17 21:07 沐阳 阅读(394) 评论(0) 推荐(0) 编辑
摘要: 这次看了这题的动态规划写法,顿时觉得好理解多了。这里要对dp[i]的意义进行一下说明,dp[i]表示从1~i包含第i个数的最大子串和,如果前i-1个数的包含i-1在内的最大和为正数的话,那么包含第i个数的最大子串和就是dp[i-1]+seq[i],否则dp[i] 就等于seq[i]了。该题的动态递归写法并没有直接给出最终答案的状态,但是却能够根据另外的状态推到出答案。这点值得我们思考。代码如下:#include <cstring>#include <cstdlib>#include <cstdio>#include <algorithm>#def 阅读全文
posted @ 2012-04-17 17:04 沐阳 阅读(422) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1864这一题的题义真的让人很伤神啊。其中不超过600元,是指某一类物品的总和不超过600元,1000元是指整张发票的钱不超过1000元,对于浮点数,我们将其统一乘以100。该题背包的体积就是发票数,对于第 i 张发票,其最大报销额就是 dp[i] = Max[ ( dp[j]+Fee[i] ) <= LIMIT], 其中dp[j]可达(满足在1~i-1张发票之前能够报销j张发票,其总和为不超过额定最大报销额的最大值)。代码如下:#include <cstdlib>#include <c 阅读全文
posted @ 2012-04-17 15:47 沐阳 阅读(277) 评论(0) 推荐(0) 编辑
摘要: 先粘上E题代码:// Code for problem E/* * by purple * at 12-04-09 2:19:41 PM */#include <cstdio>#include <algorithm>#include <cstring>#include <vector>using namespace std;#define sz(x) ((int)((x).size()))#define out(x) printf(#x" %d\n", x)#define rep(i,n) for(int i=0;i<( 阅读全文
posted @ 2012-04-16 15:36 沐阳 阅读(261) 评论(0) 推荐(0) 编辑
摘要: (转)C语言宏定义中的#,##,#@及\符号的作用来源:刘诗慧Rubby的日志1、#(stringizing)字符串化操作符 作用:将宏定义中的传入参数名转换成用一对双引号括起来参数名字符串。其只能用于有传入参数的宏定 义中,且必须置于宏定义体中的参数名前。 如:#defineexample(instr)printf("theinputstringis:\t%s\n",#instr)#defineexample1(instr)#instr 当使用该宏定义时:example(abc); 在编译时将会展开成:printf("theinputstringis:\t%s\ 阅读全文
posted @ 2012-04-16 14:50 沐阳 阅读(602) 评论(0) 推荐(0) 编辑
摘要: 题目就是概率的问题,意思是去抢A银行,被捉的概率是ai,抢B银行,被捉的概率是bi,因此不被捉的概率是(1-ai)*(1-bi)......因此整个题目我们用逃避概率来计算。代码如下:#include <cstdio>#include <cstring>#include <cstdlib> using namespace std;struct Node{ int m; double poss;}e[105];double dp[10005];int N, max;double poss;inline double Max(double x, double y 阅读全文
posted @ 2012-04-10 22:17 沐阳 阅读(236) 评论(0) 推荐(0) 编辑
摘要: 简单构图,构造一个S流向 S,M,L,X,T,赛事 T1,T2,T2...TN流向汇点T。代码如下:#include <cstdio>#include <cstdlib>#include <cstring>#include <queue>#define INF 0x3f3f3f3f#define MAXN 25using namespace std;int N, cap[40][40], flow[40][40], p[40], c[40], S = 0, T = 38;int hash[130], maxflow;void init(){ ma 阅读全文
posted @ 2012-04-05 16:28 沐阳 阅读(263) 评论(0) 推荐(0) 编辑
摘要: 不能恋爱问题。代码如下:#include <cstdlib>#include <cstdio>#include <cstring>using namespace std;int N;int G[505][505], visit[505], marry[505];struct P{ int h; char sex[5], style[105], fav[105];}p[505];int judge(int x, int y){ if (abs(p[x].h-p[y].h)>40) return 0; else if (p[x].sex[0] == p[y 阅读全文
posted @ 2012-04-05 14:32 沐阳 阅读(363) 评论(0) 推荐(0) 编辑
摘要: 题目给定N个老鼠,M个洞,在规定的时间后,将有天敌来猎捉它们,每个老鼠都有一个速度,求一种躲藏的策略,使得受威胁的老鼠最少。(每个洞中只能藏一只老鼠)该题可以将老鼠到达可及洞的情况看作是一个匹配,于是该题就是求一个老鼠到洞的最大匹配。代码如下:#include <cstdlib>#include <cstdio>#include <cstring>#include <cmath>#define MAXN 100using namespace std;int n, m, s, v;int G[MAXN+5][MAXN+5], visit[MAXN+ 阅读全文
posted @ 2012-04-05 14:04 沐阳 阅读(319) 评论(0) 推荐(0) 编辑
摘要: 不会sap,邻接矩阵过。#include <cstdlib>#include <cstring>#include <cstdio> #include <queue>#define MAXN 375#define INF 0x3f3f3f3fusing namespace std;int cap[MAXN+1][MAXN+1], flow[MAXN+1][MAXN+1], N;int p[MAXN+1], c[MAXN+1];int seq[25][15], maxflow;inline void init(){ maxflow = 0; mems 阅读全文
posted @ 2012-03-31 16:01 沐阳 阅读(194) 评论(0) 推荐(0) 编辑
上一页 1 ··· 43 44 45 46 47 48 49 50 51 ··· 66 下一页