03 2016 档案

最长上升子序列 LIS
摘要:题目: http://acm.nyist.net/JudgeOnline/problem.php?pid=17 http://poj.org/problem?id=2533 两道题几乎一样,只不过对于输入输出的要求有所不同罢了。 LIS有两种方法: 一、第一种方法 · 时间复杂度为O(n^2): 状 阅读全文

posted @ 2016-03-31 23:19 SuperChan 阅读(233) 评论(0) 推荐(0)

POJ 1141 —— Brackets Sequence
摘要:题目:http://poj.org/problem?id=1141 区间DP + 构造出DP的解 这里有两种思路都是对的: 第一种(推荐):dp[i][j] := 区间i~j最少需要加多少字符使得它符合括号匹配,然后构造出一个DP的解就好了 第二种:dp[i][j] := 区间i~j符合括号匹配的最 阅读全文

posted @ 2016-03-31 15:40 SuperChan 阅读(183) 评论(0) 推荐(0)

最长公共子序列 LCS
摘要:题目:http://acm.nyist.net/JudgeOnline/problem.php?pid=36 介绍一下定义先~ 子序列:一个序列的子序列,就是该序列删掉若干个(0~len-1)元素后的序列 公共子序列:一个序列c如果既是序列a删去若干元素后的结果,又是序列b删去若干元素后的结果,则: 阅读全文

posted @ 2016-03-31 13:54 SuperChan 阅读(385) 评论(0) 推荐(0)

POJ 3280 —— Cheapest Palindrome
摘要:题目:http://poj.org/problem?id=3280 经典的区间DP 阅读全文

posted @ 2016-03-30 22:52 SuperChan 阅读(139) 评论(0) 推荐(0)

POJ 3661 —— Running
摘要:题目:http://poj.org/problem?id=3661 这题要注意看清题意:一旦开始休息就要一直休息到疲劳值为0! 阅读全文

posted @ 2016-03-30 22:01 SuperChan 阅读(160) 评论(0) 推荐(0)

UVA - 10003 —— Cutting Sticks
摘要:题目:Cutting Sticks 很基础的一道区间DP :) 阅读全文

posted @ 2016-03-29 22:39 SuperChan 阅读(136) 评论(0) 推荐(0)

UVA - 10688 —— The Poor Giant
摘要:题目:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=36406 题目举的那个例子有些错误。。一看就能发现并且修正的:) 这道题算是最简单的区间DP问题之一了吧~以至于我很顺畅地就写出了转移方程,算是这几天训练区间DP的结果吧: 阅读全文

posted @ 2016-03-29 21:57 SuperChan 阅读(221) 评论(0) 推荐(0)

CSU 1216 —— 异或最大值
摘要:题目:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1216 阅读全文

posted @ 2016-03-29 18:34 SuperChan 阅读(301) 评论(0) 推荐(0)

HDU 2746 ——String painter
摘要:题目:http://acm.hdu.edu.cn/showproblem.php?pid=2476 这道题,大多数博客都是一种解法:就是先得到无颜色的字符串涂色为所需字符串的最小次数(1),然后基于此去找当原先的字符串并不是无颜色的而是有固定颜色时的最小值(2)。怎样找呢?因为字符串原先已有颜色, 阅读全文

posted @ 2016-03-29 14:27 SuperChan 阅读(229) 评论(0) 推荐(0)

sdut 1309 —— 不老的传说问题
摘要:题目:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1309 状态:dp[i][j] := 区间i~j都是无色时的最小涂色次数 转移:dp[i][j] = min(dp[i+1][j]+1 (单独涂色), 阅读全文

posted @ 2016-03-29 01:05 SuperChan 阅读(206) 评论(0) 推荐(0)

HDU 4283 —— You Are the One
摘要:题目:http://acm.hdu.edu.cn/showproblem.php?pid=4283 阅读全文

posted @ 2016-03-28 22:04 SuperChan 阅读(143) 评论(0) 推荐(0)

ZOJ - 3469 —— Food Delivery
摘要:题目:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3469 阅读全文

posted @ 2016-03-28 14:30 SuperChan 阅读(327) 评论(0) 推荐(0)

POJ 1651 —— Multiplication Puzzle
摘要:题目:http://poj.org/problem?id=1651 阅读全文

posted @ 2016-03-28 11:18 SuperChan 阅读(148) 评论(0) 推荐(0)

Light oj 1422 - Halloween Costumes
摘要:题目:http://lightoj.com/volume_showproblem.php?problem=1422 阅读全文

posted @ 2016-03-28 00:38 SuperChan 阅读(159) 评论(0) 推荐(0)

POJ 2955 —— Brackets
摘要:题目:http://poj.org/problem?id=2955 状态定义:dp[i][j] := 区间为i~j时的最大长度 方法1(推荐): dp[i][j] = min(dp[i+1][j],dp[i+1][k-1]+dp[k+1][j]+2)(i<=k<=j&&i和k是一对括号) 方法2: 阅读全文

posted @ 2016-03-27 22:42 SuperChan 阅读(162) 评论(0) 推荐(0)

求若干矩形的不重叠面积 —— 模拟 + 优化
摘要:Description Time Limit: 1sec Memory Limit:256MB Dr. R is a very nice man. He is very interested in social emotion classification. As a researcher in t 阅读全文

posted @ 2016-03-26 23:44 SuperChan 阅读(377) 评论(0) 推荐(0)

数组删数,求最大得分
摘要:Description Time Limit: 1sec Memory Limit:256MB The teachers of SMIE are all playing games. XM also want to play so he invents a game. The game is als 阅读全文

posted @ 2016-03-26 22:11 SuperChan 阅读(329) 评论(0) 推荐(0)

ZOJ - 3537 —— Cake
摘要:题目:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=23543 1. 因为没有三个点在同一直线上,即每个点都是多边形的一个顶点而不会有点在某条边上,所以要判断这个多边形是不是凸多边性,可以用像凸包问题那样做,得到的凸包的关节点 阅读全文

posted @ 2016-03-26 20:51 SuperChan 阅读(244) 评论(0) 推荐(0)

ZOJ - 1453 —— Surround the Trees (求凸包的周长)
摘要:题目:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=20416 这道题几乎是纯的“凸包问题”,也让我对于凸包有了入门级的认识。 我看到的比较好的算法是Graham扫描法,用笔模拟了一下该算法,大致就对该算法有所体会了,所以碰到 阅读全文

posted @ 2016-03-26 18:49 SuperChan 阅读(385) 评论(0) 推荐(0)

UVAlive - 3516 —— Exploring Pyramids
摘要:题目:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=27284 这道题要我们求树的个数,是一道枚举的题目,关键在于不重不漏地去枚举 这里给出了一种思路: 每一次固定一种“最左边的儿子节点的子树”,剩下的节点任意排布。 然后,通 阅读全文

posted @ 2016-03-25 13:25 SuperChan 阅读(222) 评论(0) 推荐(0)

UVA - 11806 —— Cheerleaders
摘要:题目:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=31969 这题正向去枚举比较困难,我们都知道“正难则反”,可以去考虑反向枚举的方法: 1. 先枚举没有条件约束时的个数 2. 然后,减去不满足条件的个数 3. 这里要注意, 阅读全文

posted @ 2016-03-25 01:23 SuperChan 阅读(151) 评论(0) 推荐(0)

UVA - 11401 —— Triangle Counting
摘要:题目:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=22646 1. 因为三角形的三条边均不同,所以不妨令z<y<x 2. 所以,对于固定的x和y,基于三角形不等式z+y>x,z的范围是已知的: x-y < z < y 3. 阅读全文

posted @ 2016-03-24 22:55 SuperChan 阅读(208) 评论(0) 推荐(0)

UVA - 11538 —— Chess Queen
摘要:题目:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=28978 1. 两个皇后在同一行、同一列时候的情况很简单,其实就是n*C(m,2)+m*C(n,2) 2. 这道题可以通过一个3*5的方格矩形来找到对角线冲突的规律,我们都 阅读全文

posted @ 2016-03-24 20:19 SuperChan 阅读(170) 评论(0) 推荐(0)

UVAlive - 4794—— Sharing Chocolate
摘要:题目:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=12055 由于n<=15, 所以可以很明显猜测出这道题可能可以用状态压缩dp来求解。 问题的关键是:dp的状态要如何设计才能既达到目的,又能减少时间、空间复杂度。 最容易想 阅读全文

posted @ 2016-03-24 14:25 SuperChan 阅读(240) 评论(0) 推荐(0)

UVAlive - 3983—— Robotruck
摘要:题目:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=13674 1.首先要明确货物必须要按照输入的顺序依次寄出,而且每一次携带有容量限制,所以可以理解成对于前n个货物的投递问题(dp[n]),我们要找一个任意合适的下标k,使得 阅读全文

posted @ 2016-03-24 12:34 SuperChan 阅读(254) 评论(0) 推荐(0)

快速排序 ——双游标、单游标实现
摘要:#include #include using namespace std; // 双游标版本 int* partition(int *l, int *r) { int *i = l+1, *j = r-1; int aim = *l, temp; while(iaim) j--; if(iaim | unknown], k指向第一个>aim... 阅读全文

posted @ 2016-03-22 15:58 SuperChan 阅读(254) 评论(0) 推荐(0)

归并排序 + 逆序数
摘要:#include #include using namespace std; int ans = 0; void merge(int* l, int* mid, int *r) { int b[r-l]; int *i = l, *j = mid, cur = 0; while(i=r || *i <= *j)) b[cur++] = *i++; ... 阅读全文

posted @ 2016-03-22 13:58 SuperChan 阅读(142) 评论(0) 推荐(0)

Sicily - 1381 大数乘法
摘要:题目:http://soj.sysu.edu.cn/1381 阅读全文

posted @ 2016-03-22 10:22 SuperChan 阅读(203) 评论(0) 推荐(0)

Sicily - 1159 大数加法
摘要:#include #include #include #include using namespace std; // http://soj.sysu.edu.cn/1159 string a, b; void add(string& a, string& b) { if(a.size() =0; i--, j--) { sum += a[i]-'0'; ... 阅读全文

posted @ 2016-03-21 22:18 SuperChan 阅读(142) 评论(0) 推荐(0)

经典面试题——二叉树
摘要:#include #include #include using namespace std; struct Node { Node *l, *r; int x; Node(int x=0, Node *l=NULL, Node *r=NULL):x(x),l(l),r(r) {} }; class Tree { public: ... 阅读全文

posted @ 2016-03-21 20:30 SuperChan 阅读(219) 评论(0) 推荐(0)

UVA - 10859 —— Placing Lampposts
摘要:题目:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=34290 这道题是一道在树上面搜索的好题,要注意以下几点: 1. 如何将该问题转化为最小化问题?而且这个最小化问题有两个最小化目标,首要的是“点数”,其次是“仅被一盏灯照亮 阅读全文

posted @ 2016-03-21 16:45 SuperChan 阅读(196) 评论(0) 推荐(0)

UVA - 11825 —— Hackers' Crackdown
摘要:题目:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18913 这道题是一道状态压缩DP的好题,有几点要注意的: 1.uva给出的题目不知道为何,题意是有些描述不清的,详见《训练指南》 2.这道题可以有很多写法,整个的dp求解 阅读全文

posted @ 2016-03-19 21:57 SuperChan 阅读(251) 评论(0) 推荐(0)

UVA - 10891 —— Game of Sum
摘要:题目:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=19461 这道题是一道很好的线性DP的题目,这种双头都可以选取的,可以运用带有头、尾位置信息的状态 dp[i][j] := 以第i位开头,第j位结尾的子问题的最优解 dp[ 阅读全文

posted @ 2016-03-19 20:17 SuperChan 阅读(152) 评论(0) 推荐(0)

UVA - 10635 —— Prince and Princess
摘要:题目:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=19051 首先,这题一看就知道是——最长公共子序列(LCS) 但是,会发现这道题的字符串长度可能达到62500,我们现在会的LCS的解法时间复杂度为O(n^2),所以是会超 阅读全文

posted @ 2016-03-19 18:09 SuperChan 阅读(552) 评论(0) 推荐(0)

UVALive - 3882 —— And Then There Was One
摘要:题目:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=11350 约瑟夫环问题 这道题问的是最后死的是那个数字,所以可以不需要模拟,直接通过递推来推出最后幸存的那个数字: 声明:这里我们将所有人的编号都减1。比如8个人的编号变为 阅读全文

posted @ 2016-03-19 17:21 SuperChan 阅读(229) 评论(0) 推荐(0)

UVALive - 3905 —— Meteor 流星
摘要:题目:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=16454 1.对于每一颗流星而言,真正有意义的是它穿越矩形的有效时间,所以其实我们需要得到所有流星的有效时间 2.这样的话,原问题就转化更加具体的:某个时刻最多同时穿过多少 阅读全文

posted @ 2016-03-18 00:49 SuperChan 阅读(310) 评论(0) 推荐(0)

uva 11292 ——The Dragon of Loowater
摘要:传送门:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=19048 为了节省开支,但是又想完成杀死所有恶龙的任务,我们可以采用贪心的策略: 1.将所有骑士身高排序,将所有恶龙的头按照直径排序 2.依次让当前最弱的骑士去“挑战”, 阅读全文

posted @ 2016-03-18 00:17 SuperChan 阅读(102) 评论(0) 推荐(0)

uva 12097—— Pie
摘要:题目: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=42065 阅读全文

posted @ 2016-03-17 22:43 SuperChan 阅读(191) 评论(0) 推荐(0)

uva 12124 —— Assemble
摘要:题目: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=42087 阅读全文

posted @ 2016-03-17 22:36 SuperChan 阅读(232) 评论(0) 推荐(0)

uva 11729 —— Commando War
摘要:题目:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=28436 首先,直观的感受是: 每一个任务的交待时间是不可避免的,而且每一个交待时间后面都跟着一个执行时间。最后的总时间一定是全部交待时间之和加上某一个任务所带来的部分执行 阅读全文

posted @ 2016-03-17 22:24 SuperChan 阅读(136) 评论(0) 推荐(0)

导航