2011年8月7日

ACM PKU 3342 Party at Hali-Bula http://poj.org/problem?id=3342

摘要: 好久没有认真写过解题报告了,今天白天做题做纠结了,晚上趁着这个纠结的时间好好写一个题的解题报告吧,希望我的报告后来者能看懂;ACM PKU 3342 Party at Hali-Bula http://poj.org/problem?id=3342这道题;题目大意是:一个聚会要邀请最多的人参加,但是又担心老板和员工在一起会玩得不高兴,所以老板去了那么他得直属员工就不能去,题目最终目的是找一个解决方案找到一个最优解(即最多人数)同时回答这个问题是不是唯一解。对于求解问题dp[i][2]=0标示当前节点不参加聚会,dp[i][2]=1表示当前节点参加聚会;有如下状态转移方程:dp[u][0]+=m 阅读全文

posted @ 2011-08-07 18:57 _Clarence 阅读(220) 评论(0) 推荐(0) 编辑

链式前向星

摘要: 1 struct node 2 { 3 int from,to, next; //next表示下一条边; 4 }; 5 node edge [maxm]; 6 int ecnt,box[maxn]; //box[]第一个节点; 7 void _make_map(int from,int to) 8 { 9 edge[ecnt].to=to;10 edge[ecnt].next=box[from];11 box[from]=ecnt++;12 }13 void make_map(int from,int to)14 {15 _make_map(fr... 阅读全文

posted @ 2011-08-07 10:54 _Clarence 阅读(145) 评论(0) 推荐(0) 编辑

已知数的前序和中序遍历,求后序遍历和层序遍历的序列

摘要: 树的存储结构定为链式存储结构,首先需要建树buildTree(),然后用递归遍历PostTraverse()产生后序遍历,借用队列实现层序遍历:实现代码:#include <iostream>#include <string>#include <queue>using namespace std;struct TreeNode{ char val; TreeNode *left,*right;};TreeNode * bulidTree(string pre,string in){ TreeNode * root =NULL; if (pre.length( 阅读全文

posted @ 2011-08-07 10:52 _Clarence 阅读(411) 评论(0) 推荐(0) 编辑

ACM PKU 1157 LITTLE SHOP OF FLOWERS http://poj.org/problem?id=1157

摘要: 明显的动态规划题,状态转移方程为:dp[i][j]=max{(dp[i-1][j-1]+A[i]),dp[i][j]};下面附上我的代码:#include <iostream>#include <string.h>#include <stdio.h>const int inf=0x3fffffff;const int maxn=101;using namespace std;int dp[maxn][maxn],num[maxn][maxn];void solve(int bunches,int vases){ for(int i=0;i<vases; 阅读全文

posted @ 2011-08-07 10:16 _Clarence 阅读(97) 评论(0) 推荐(0) 编辑

导航