摘要: 1046. Plane SpottingConstraintsTime Limit: 1 secs, Memory Limit: 32 MBDescriptionCraig is fond of planes. Making photographs of planes forms a major part of his daily life. Since he tries to stimulate his social life, and since it’s quite a drive from his home to the airport, Craig tries to be very 阅读全文
posted @ 2013-08-21 23:06 中大黑熊 阅读(987) 评论(0) 推荐(0) 编辑
摘要: 题目不算很难,dp的转移方程也很容易列出:设dp[i][j] 代表第i次传球之后球回到j手中的传球数。易得:dp[i][j] = dp[i-1][j-1] + dp[i-1][j-1] 再处理一下头头尾尾即可。 1 #include 2 #include 3 using namespace std; 4 int dp[32][32]; 5 int main() 6 { 7 int n,m; 8 while(cin >> n >> m) 9 {10 memset(dp,0,sizeof(dp));11 int i,j;12 ... 阅读全文
posted @ 2013-08-18 16:56 中大黑熊 阅读(314) 评论(0) 推荐(0) 编辑
摘要: 这道题目想了一会儿觉得不知道如何下手,上网看了下资料,原来这道是一道非常经典的题目。设 f [ k ][ i ][ j ] 表示第 k 步,第 1 条路径走到第 i 行,第 2 条路径走到第 j 行的最大权值和。 状态转移方程: f [ k ][ i ][ j ] = max { f [ k - 1 ][ i - 1 ][ j ], f [ k - 1 ][ i ][ j - 1 ], f [ k - 1 ][ i ][ j ], f [ k - 1 ][ i - 1 ][ j - 1 ] } + map[ i ][ k - i ] + map[ j ][ k - j ] ( 2 #inclu 阅读全文
posted @ 2013-08-18 11:57 中大黑熊 阅读(379) 评论(0) 推荐(0) 编辑
摘要: 1762. 排座椅ConstraintsTime Limit: 1 secs, Memory Limit: 32 MBDescription上课的时候总有一些同学和前后左右的人交头接耳,这是令小学班主任十分头疼的一件事情。不过,班主任小雪发现了一些有趣的现象,当同学们的座次确定下来之后,只有有限的D对同学上课时会交头接耳。同学们在教室中坐成了M行N列,坐在第i行第j列的同学的位置是(i,j),为了方便同学们进出,在教室中设置了K条横向的通道,L条纵向的通道。于是,聪明的小雪想到了一个办法,或许可以减少上课时学生交头接耳的问题:她打算重新摆放桌椅,改变同学们桌椅间通道的位置,因为如果一条通道隔开 阅读全文
posted @ 2013-08-16 13:21 中大黑熊 阅读(730) 评论(0) 推荐(0) 编辑
摘要: 2013. Pay BackConstraintsTime Limit: 1 secs, Memory Limit: 256 MBDescription"Never a borrower nor a lender be." O how Bessie wishes she had taken that advice! She has borrowed from or lent money to each of N (1 ≤ N ≤ 100,000) friends, conveniently labeled 1..N.Payback day has finally come. 阅读全文
posted @ 2013-08-16 10:48 中大黑熊 阅读(440) 评论(0) 推荐(0) 编辑
摘要: 给出四个数字,要求,在其间添加运算符和括号,使得计算结果等于24。括号的放置即为决定哪几个数先进行计算。所以,我们先确定首先进行计算的两个相邻的数,计算完成后,就相当于剩下三个数字,仍需要在它们之间添加符号;然后再决定在这三个数中哪两个相邻的数先计算。由此,我们就成功解决了数字的运算次序问题,此时不需要再考虑不同运算符号的优先级问题,因为括号的优先级高于加减乘除。通过循环,我们可以得到第一第二第三次计算的运算符,再通过计算,就可以得出和,若和等于24,即为所求解。在输出格式中,由于括号的放置共六种情况,故根据计算先后顺序的不同,输出时在不同地方放置括号;以下是java源码:import jav 阅读全文
posted @ 2013-08-15 12:22 中大黑熊 阅读(9801) 评论(12) 推荐(1) 编辑
摘要: DescriptionThere are n children in a country marked by integers from 1 to n.They often fight with each other. For each pair of child A and child B, either A beats B or B beats A. It is not possible that both A beats B and B beats A. Of course, one never fight with himself.Child A is not afraid of ch 阅读全文
posted @ 2013-08-13 21:38 中大黑熊 阅读(382) 评论(0) 推荐(0) 编辑
摘要: DescriptionOn one of my many interplanetary travels I landed on a beautiful little planet called Crucible. It was inhabited by an extremely peace-loving people who called themselves Snooks. They received me very gracefully and told me I had arrived at precisely the right time, as the biggest event o 阅读全文
posted @ 2013-08-12 23:33 中大黑熊 阅读(400) 评论(0) 推荐(0) 编辑
摘要: 最长递增子序列(LIS)本博文转自作者:Yx.Ac 文章来源:勇幸|Thinking(http://www.ahathinking.com)---最长递增子序列又叫做最长上升子序列;子序列,正如LCS一样,元素不一定要求连续。本节讨论实现三种常见方法,主要是练手。题:求一个一维数组arr[i]中的最长递增子序列的长度,如在序列1,-1,2,-3,4,-5,6,-7中,最长递增子序列长度为4,可以是1,2,4,6,也可以是-1,2,4,6。方法一:DP像LCS一样,从后向前分析,很容易想到,第i个元素之前的最长递增子序列的长度要么是1(单独成一个序列),要么就是第i-1个元素之前的最长递增子序列 阅读全文
posted @ 2013-08-08 20:20 中大黑熊 阅读(311) 评论(0) 推荐(0) 编辑
摘要: 今天学习到TreeSet,但是它是按照key的值来排序的,那如果我们想要按照value的值排序呢?这个问题我上网看了好久,终于找到一个比较易懂的例子:例:(统计输入数字的个数)话不多说,看代码就懂import java.util.*;import java.util.Scanner;public class CountNum { public static void main(String[] args){ HashMap hashMap = new HashMap(); Scanner input = new Scanner(System.in); int num = input.n... 阅读全文
posted @ 2013-08-08 12:09 中大黑熊 阅读(1458) 评论(0) 推荐(0) 编辑