随笔分类 -  UVA_2

摘要:挺简单的先谈状态 dp[i][j]表示i---j之间的最少需要加的括号数再谈转移 if S 为 合法序列 那么 (S),[S] 都为合法序列,那么dp[i][j] = dp[i +1][j - 1];if A 为合法序列 && B为合法序列 那么 AB 为合法序列 dp[i][j] = dp[i][... 阅读全文
posted @ 2015-02-21 14:38 闪光阳 阅读(220) 评论(0) 推荐(0)
摘要:类似矩阵连乘的一道题,很简单DP[i][j]表示区间i,j最少费用,状态转移为DP[i][j] = min{DP[i][k],DP[k][j]} + a[j] - a[i]; 1 #include 2 #include 3 #include 4 #include 5 6 #define R... 阅读全文
posted @ 2015-02-17 18:32 闪光阳 阅读(217) 评论(0) 推荐(0)
摘要:题目很容易,找到状态DP[i] 表示前 i 个字符中最少的划分,那么转移DP[i] = min {DP[j] + 1 | s[j +1]...s[i] 为 palindromes} 1 #include 2 #include 3 #include 4 #include 5 6 #defin... 阅读全文
posted @ 2015-02-17 15:16 闪光阳 阅读(210) 评论(0) 推荐(0)
摘要:题目很简单,LIS变形 1 #include 2 #include 3 #include 4 #include 5 #include 6 7 #define REP(i,N) for (int i = 0;i = 0;i--)10 #define INF 0x3f3f3f3f11 #de... 阅读全文
posted @ 2015-02-17 13:32 闪光阳 阅读(139) 评论(0) 推荐(0)
摘要:谈到背包,大家肯定都熟悉,我就不多讲,而这题挺有意思。DP[i][j] 表示前 i 首歌在j时间内唱的最多曲目;状态有了,那么怎么转移呢? DP[i][j] = max{DP[i - 1][j],DP[i - 1][j - t[i]] + 1};但是此题还有时间。所以如果初始化为0的话,按照平常背包... 阅读全文
posted @ 2015-02-15 20:50 闪光阳 阅读(195) 评论(0) 推荐(0)
摘要:一道比较简单的动态规划的题,求从第一列的任何位置 到达最后一列 和的最小值。所以这个状态可以是 列,在每一列有三种决策,直行,右上,右下。DP[i][j] 表示在第i行,j列到达最后一列的最小支出。那么有了状态,我们可以进行转移,DP[i][j] = min{DP[i + 1][j + 1],DP[... 阅读全文
posted @ 2015-02-15 17:26 闪光阳 阅读(107) 评论(0) 推荐(0)
摘要:由于事情的耽误,导致第二天出来的有点慢,今天是我学动态规划的第二天,做了一个DAG上的最长路。一个立方体的高有三个,然后判断个点之间是否可以连接,然后DAG搞定#include #include #include #include #define REP(i,N) for(int i = 0;i >... 阅读全文
posted @ 2015-02-13 19:20 闪光阳 阅读(115) 评论(0) 推荐(0)
摘要:2015年2月11日,我开始了我的DP之路,也不知道能不能掌握,只能一点点的积累了。这是我的第一题UVA1025 (A Spy in the Metro);题目的意思很清楚了,当你在一个汽车站的时候,你之后两种选择,一是等着,二是上车(前提有车),当然有车的时候也可以不做,无所谓;当然有车,也要看方... 阅读全文
posted @ 2015-02-11 17:54 闪光阳 阅读(255) 评论(0) 推荐(0)
摘要:这是我人生中的第一个计算几何题,好好收藏一下。1、当一个点关于远点对称之后,除了两点之间的连线外,其他的任何直线都会讲两点分成两个部分2、极角排序3、线的旋转4、叉积求 sin#include #include #include #include using namespace std;class ... 阅读全文
posted @ 2015-02-09 10:29 闪光阳 阅读(489) 评论(0) 推荐(0)
摘要:struct Hash_map { static const int mask=0x7fffff; int p[8388608],q[8388608]; void clear() { for(int i=0; i<=mask; ++i) ... 阅读全文
posted @ 2015-02-07 15:57 闪光阳 阅读(111) 评论(0) 推荐(0)
摘要:StampsThe government of Nova Mareterrania requires that various legal documents have stamps attached to them so that the government can derive revenue... 阅读全文
posted @ 2014-11-29 15:51 闪光阳 阅读(185) 评论(0) 推荐(0)
摘要:How Big Is It?Ian's going to California, and he has to pack his things, including his collection of circles. Given a set of circles, your program must... 阅读全文
posted @ 2014-11-29 10:13 闪光阳 阅读(167) 评论(0) 推荐(0)
摘要:Mapping the SwapsSorting an array can be done by swapping certain pairs of adjacent entries in the array. This is the fundamental technique used in th... 阅读全文
posted @ 2014-11-28 19:56 闪光阳 阅读(194) 评论(0) 推荐(0)
摘要:TransportationRuratania is just entering capitalism and is establishing new enterprising activities in many fields including transport. The transporta... 阅读全文
posted @ 2014-11-28 19:28 闪光阳 阅读(208) 评论(0) 推荐(0)
摘要:Problem I23 Out of 5Input:standard inputOutput:standard outputTime Limit:1 secondMemory Limit:32 MBYour task is to write a program that can decide whe... 阅读全文
posted @ 2014-11-28 12:35 闪光阳 阅读(159) 评论(0) 推荐(0)
摘要:Don't Get RookedIn chess, the rook is a piece that can move any number of squares vertically or horizontally. In this problem we will consider small c... 阅读全文
posted @ 2014-11-28 11:59 闪光阳 阅读(142) 评论(0) 推荐(0)
摘要:Getting in LineComputer networking requires that the computers in the network be linked.This problem considers a ``linear" network in which the comput... 阅读全文
posted @ 2014-11-28 10:43 闪光阳 阅读(138) 评论(0) 推荐(0)
摘要:Meta-Loopless SortsBackgroundSorting holds an important place in computer science. Analyzing and implementing various sorting algorithms forms an impo... 阅读全文
posted @ 2014-11-28 09:39 闪光阳 阅读(141) 评论(0) 推荐(0)
摘要:ID CodesIt is 2084 and the year of Big Brother has finally arrived, albeit a century late. In order to exercise greater control over its citizens and ... 阅读全文
posted @ 2014-11-26 20:36 闪光阳 阅读(208) 评论(0) 推荐(0)
摘要:BandwidthGiven a graph (V,E) where V is a set of nodes and E is a set of arcs in VxV, and anorderingon the elements in V, then thebandwidthof a nodevi... 阅读全文
posted @ 2014-11-26 19:18 闪光阳 阅读(163) 评论(0) 推荐(0)