11 2012 档案

摘要:卡特兰数高精度。View Code 1 /* 2 Author:Zhaofa Fang 3 Lang:C++ 4 */ 5 #include <cstdio> 6 #include <cstdlib> 7 #include <sstream> 8 #include <iostream> 9 #include <cmath>10 #include <cstring>11 #include <algorithm>12 #include <string>13 #include <utility> 阅读全文
posted @ 2012-11-28 19:42 發_ 阅读(226) 评论(0) 推荐(0)
摘要:poj这题数据很水很容易过,然而hdu的这题可能是因为case太多O(125*125*n)的复杂度TLE,最后用了快速幂的方法优化到O(125*125*logn)过了。140MS。View Code 1 /* 2 Author:Zhaofa Fang 3 Lang:C++ 4 */ 5 #include <cstdio> 6 #include <cstdlib> 7 #include <sstream> 8 #include <iostream> 9 #include <cmath> 10 #include <cstring&g 阅读全文
posted @ 2012-11-28 14:02 發_ 阅读(237) 评论(0) 推荐(0)
摘要:题意:有n个垃圾,机器人要按照编号从小到大捡但手中的垃圾不得超过C,求出机器人行走的最短总路程。做法:设dp[i]为捡第i个垃圾的最短距离,dist[i]为按顺序的总长,dis_ori[i]为i到原点的距离。不难得出:dp[i] = min{dp[j] + dis_ori[j+1] + distance[j+1,i] + dis_ori[i] } ; w(j+1,i)<=C = min{dp[j] + dis_ori[j+1] - dist[j+1]} + dist[i] + dis_ori[i] ; w(j+1,i)<=C用单调队列可以解决min的值,复杂度O(n... 阅读全文
posted @ 2012-11-18 11:16 發_ 阅读(344) 评论(0) 推荐(0)
摘要:http://codeforces.com/contest/242C题:给出一些线段,起点和终点,只能在线段上走,线段范围上限为1e9,但是线段的总长不超过1e5.做法:bfs+mapView Code 1 /* 2 Author:Zhaofa Fang 3 Lang:C++ 4 */ 5 #include <cstdio> 6 #include <cstdlib> 7 #include <sstream> 8 #include <iostream> 9 #include <cmath>10 #include <cstring& 阅读全文
posted @ 2012-11-13 13:25 發_ 阅读(269) 评论(0) 推荐(0)
摘要:题意:给定一个长度为n的整数序列,求一个最长子序列,使得该序列的长度为2*k+1,前k+1个数严格递增,后k+1个数严格递减。分析:用O(nlogn)分别求出递增序列和递减序列,再O(n)求在某个位置符合条件的序列长度。View Code 1 /* 2 Author:Zhaofa Fang 3 Lang:C++ 4 */ 5 #include <cstdio> 6 #include <cstdlib> 7 #include <sstream> 8 #include <iostream> 9 #include <cmath>10 #in 阅读全文
posted @ 2012-11-10 15:11 發_ 阅读(205) 评论(0) 推荐(0)
摘要:题意:把字符串划分成尽量少的回文串。dp[i] = max{dp[j-1] + 1 | str[j....i]为回文串}。View Code 1 /* 2 Author:Zhaofa Fang 3 Lang:C++ 4 */ 5 #include <cstdio> 6 #include <cstdlib> 7 #include <sstream> 8 #include <iostream> 9 #include <cmath>10 #include <cstring>11 #include <algorithm> 阅读全文
posted @ 2012-11-08 22:58 發_ 阅读(519) 评论(0) 推荐(0)
摘要:又是训练指南上的一道经典题~~ http://uva.onlinejudge.org/external/106/10635.html题意:有两个长度分别为p+1和q+1的序列,每个序列各个元素互不相同,且都是1~n^2的整数。求俩序列的LCS。分析:LCS的O(pq)复杂度显然太慢。注意到“每个序列各个元素互不相同,且都是1~n^2的整数”,所以有个巧妙的转换,把A中的元素重新按1~p+1编号,同时B也相同的映射编号,由于A为递增序列,所以LCS就是B中最长递增子序列,即LIS.这样就转换成求B的LIS问题,可以在O(nlogn)的时间内解决。LIS:设dp[i]为以A[i]结尾的最长上升子序 阅读全文
posted @ 2012-11-06 20:47 發_ 阅读(334) 评论(0) 推荐(0)