摘要: http://poj.org/problem?id=1065DP,最长“上升”子序列 1 #include <stdio.h> 2 #include <stdlib.h> 3 4 struct Sticks 5 { 6 int x, y; 7 }s[5432]; 8 9 int n, dp[5432];10 11 int cmp1(struct Sticks a, struct Sticks b)12 {13 return a.x < b.x || a.y < b.y;14 }15 16 int LIS()17 {18 int i, j, max1, max 阅读全文
posted @ 2013-01-20 01:09 Yuan1991 阅读(136) 评论(0) 推荐(0)
摘要: http://poj.org/problem?id=3250单调队列,栈模拟有 n 头牛头朝东站成一列。每头牛有一定的高度,并且能看到其前面高度比它低的牛的头顶,直到被某头高度大于等于它的高度的牛所挡住。计算每头牛能看到的牛头顶的数量之和。 1 #include <stdio.h> 2 #include <stack> 3 4 using namespace std; 5 6 stack<pair<int, int> > s; 7 long long sum = 0; 8 9 void push(int a, int i)10 {11 while 阅读全文
posted @ 2013-01-19 15:12 Yuan1991 阅读(149) 评论(0) 推荐(0)
摘要: http://poj.org/problem?id=2704基础DP 1 #include <stdio.h> 2 3 int main() 4 { 5 int i, j, k, n, map[36][36]; 6 long long dp[36][36]; 7 char c; 8 while(scanf("%d%*c", &n), ~n) 9 {10 //init11 for(i=1; i<=n; i++)12 {13 for(j=1; j<=n; j++)14 ... 阅读全文
posted @ 2013-01-17 16:17 Yuan1991 阅读(132) 评论(0) 推荐(0)
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1829并查集,二分图识别如果A喜欢B,不能直接判断A,B的性别,但是可以知道,A喜欢的人和B是同性的(一个集合)。不直接合并A,B所在集合,而间接合并A喜欢的人所在集合 与 B所在集合,使问题得到简化。建立一个like数组,储存A喜欢的一个人为like[A](任意一个都可以),1.初始化:开始让每个人喜欢自己,like[i] = i;在执行合并操作(3)之前,如果A,B双方中还有喜欢自己的,则调整为喜欢对方,like[A] = B, like[B] = A;2.查询操作:如果A和B在一个集合中,则AB属于同性 阅读全文
posted @ 2013-01-15 15:28 Yuan1991 阅读(166) 评论(0) 推荐(0)
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1856并查集,集合计数多加一个sum数组,统计集合元素个数,初始化为1 1 #include <stdio.h> 2 #define N 10001000 3 4 int n, f[N], sum[N], max = 1;//f-->father 5 6 int find(int x) 7 { 8 return x-f[x]? f[x]=find(f[x]): x; 9 }10 11 void merge(int x, int y)12 {13 int r1, r2;//r-->roo 阅读全文
posted @ 2013-01-15 14:02 Yuan1991 阅读(162) 评论(0) 推荐(0)