随笔分类 -  Algorithm

摘要:1.构造 void build(int node, int begin, int end);主要思想是递归构造,如果当前节点记录的区间只有一个值,则直接赋值,否则递归构造左右子树,最后回溯的时候给当前节点赋值#include using namespace std; const int m... 阅读全文
posted @ 2015-11-13 21:30 Gssol 阅读(218) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4039题目分类:字符串+bfs题意:给一个人际关系图,根据关系图,给一个人推荐一个人认识题目分析:根据样例画出的关系图代码:#includeusing namespace std;const int N=... 阅读全文
posted @ 2015-11-13 00:02 Gssol 阅读(207) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4034题目分类:图论题意:n个顶点,然后给出从i到j的最短路径长度,求至少需要哪些边第二组样例第三组样例:题目分析:判断 a[i][j]==a[i][k]+a[k][j](详看代码)代码:#include... 阅读全文
posted @ 2015-11-12 22:18 Gssol 阅读(156) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4442题意:去体检,求做完所有检查所花费的最小时间模上一个数 花费的时间规则如下 有n项活动,每项活动有两个数字 a b a代表现在去排队所花费的时间 b代表每一秒该活动需要等待的时间是多b秒... 阅读全文
posted @ 2015-11-12 15:50 Gssol 阅读(112) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=275http://acm.hust.edu.cn/vjudge/contest/view.action?cid=98837#problem/A题目分类:高斯消元题意:给定n个数,从中选择任意个... 阅读全文
posted @ 2015-11-10 23:30 Gssol 阅读(386) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=98837#problem/I题意:给定一些数,求这些数中异或值最大的值分析:每个数都可以写成二进制,可以建立一颗字典树#includeusing namespace std;#de... 阅读全文
posted @ 2015-11-10 23:14 Gssol 阅读(1377) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5115题目分类:区间dp题意:有n只狼,每只狼有两种属性,一种攻击力一种附加值,我们没杀一只狼,那么我们受到的伤害值为这只狼的攻击值与它旁边的两只狼的附加值的和,求把所有狼都杀光受到的最小的伤害值。题目分... 阅读全文
posted @ 2015-11-10 21:05 Gssol 阅读(158) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5122题目分类:思维题题意:n个数字,将它变成一个升序序列需要变换几次,几个例子深入理解52 3 4 5 1(4)3 4 1 5 2(3)题目分析:最先想的是直接两重循环来做,超时 后来想可能是最长上升子... 阅读全文
posted @ 2015-11-10 20:57 Gssol 阅读(142) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5113题目分类:dfs题意:N M K N*M的棋盘 K种颜色 接下来K个数字分别代表每种颜色的数目 要求 相邻的格子的颜色不能相同,输出一种方案就好题目分析:因为N和M的范围比较小,而且找到一种就好,... 阅读全文
posted @ 2015-11-10 20:40 Gssol 阅读(230) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://poj.org/problem?id=2479题目分类:动态规划代码:#include#include#include#includeusing namespace std;int a[50000+100];int s[50000+100];int main(){ //... 阅读全文
posted @ 2015-11-08 15:23 Gssol 阅读(139) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://poj.org/problem?id=2392题目分类:动态规划代码:#include#include#include#include#includeusing namespace std;#define INF 0x3f3f3f3fint n;bool f[40010];i... 阅读全文
posted @ 2015-11-08 15:21 Gssol 阅读(189) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://poj.org/problem?id=3666题目分类:动态规划代码:#include#include#include#include#includeusing namespace std;//用dp[i][j]表示:前i个数构成的序列,这个序列最大值为j,dp[i][j]的... 阅读全文
posted @ 2015-11-06 23:33 Gssol 阅读(138) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://poj.org/problem?id=1631题目分类:动态规划代码:#include#include#include#include#includeusing namespace std;#define INF 0x3f3f3f3fint n;int a[50500];in... 阅读全文
posted @ 2015-11-06 23:30 Gssol 阅读(206) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://poj.org/problem?id=1065题目分类:动态规划代码:#include#include#include#include#includeusing namespace std;#define INF 0x3f3f3f3fint n;int visit[5050]... 阅读全文
posted @ 2015-11-06 23:25 Gssol 阅读(147) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://poj.org/problem?id=3046题目分类:动态规划+滚动数组优化代码:#include#include#include#includeusing namespace std;int s[2000];int dp[3][100086];int main(){ ... 阅读全文
posted @ 2015-11-05 21:06 Gssol 阅读(139) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://poj.org/problem?id=1287题目分类:最小生成树代码://#include#include#include#includeusing namespace std;const int V=200;#define INF 0x3f3f3f3fint cost[V... 阅读全文
posted @ 2015-11-05 00:08 Gssol 阅读(125) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://poj.org/problem?id=1742http://acm.hdu.edu.cn/showproblem.php?pid=2844题目分类:动态规划代码:#include#include#include#includeusing namespace std;int n... 阅读全文
posted @ 2015-11-04 23:08 Gssol 阅读(152) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://poj.org/problem?id=3616题目分类:动态规划代码:#include#include#include#includeusing namespace std;int n,m,r;int dp[2000];struct P{ int a,b,c;}poin... 阅读全文
posted @ 2015-11-04 23:05 Gssol 阅读(142) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://poj.org/problem?id=3176题目分类:动态规划代码://#include#include#include#include#includeusing namespace std;int n;int a[500][500];int dp[500][500];in... 阅读全文
posted @ 2015-11-03 22:58 Gssol 阅读(101) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://poj.org/problem?id=2229题目分类:动态规划代码:分析:1121 1231 1 11 241 1 1 11 1 22 2451 1 1 1 11 1 1 21 2 21 461 1 1 1 1 11 1 1 1 21 1 2 21 1 42 2 22 47... 阅读全文
posted @ 2015-11-03 22:56 Gssol 阅读(96) 评论(0) 推荐(0) 编辑