2012年9月5日

二维DP 建房子

摘要: 题目要求: 求最大正方形边长: 输入a[][];为1则可以建房,为0则不可建房,求可以建房的最大正方形边长。 子问题:dp[i][j] 表示以a[i][j]为左上角的正方形的最大边长。 Dp[i][j]=min{dp[i-1][j], dp[i][j-1], dp[i-1][j-1]}+1可以从最尾端开始。 最后的答案为dp[][]中的最大值。代码实现:View Code 1 #include<iostream> 2 using namespace std; 3 int dp[100][100]; //dp[i][j] means start by a[i][j],the la.. 阅读全文

posted @ 2012-09-05 21:52 yumao 阅读(321) 评论(0) 推荐(0) 编辑

STl 中set的用法

摘要: set为集合其特征就是集合中没有相同的元素所以在要求去重时,可以用到集合。基本用法: set <int> sett; 初始化 sett.insert(1); 插入元素(如果集合中存在此元素,则相当于这个操作无效) sett.find(2); 这个函数还有接下来的begin(),end()等,都返回的是迭代器;如果可以找到2,那么返回的迭代器的值为2,如果找不到,则返回end()的值 set <int> ::iterator it1 迭代器 set.erase(2);删除集合中的元素2,如果集合中没有这个元素,则操作无效,另外也可以是迭代器。 for(it1=sett.b 阅读全文

posted @ 2012-09-05 21:49 yumao 阅读(167) 评论(0) 推荐(0) 编辑

线段树优化 lazy算法 poj3468

摘要: A Simple Problem with IntegersTime Limit: 5000MSMemory Limit: 131072KTotal Submissions: 35742Accepted: 10240Case Time Limit: 2000MSDescriptionYou have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of operation is to add some given number to each number in a gi 阅读全文

posted @ 2012-09-05 21:30 yumao 阅读(2891) 评论(0) 推荐(0) 编辑

线段树的实现(求段和)

摘要: View Code 1 #include<iostream> 2 #include<stdio.h> 3 using namespace std; 4 struct node{ 5 int r; //root to the right's range 6 int l; 7 node * rt; //the subtree of root's right 8 node * lt; 9 __int64 key; //the value of the root,... 阅读全文

posted @ 2012-09-05 21:11 yumao 阅读(190) 评论(0) 推荐(0) 编辑

DP poj 2192

摘要: ZipperTime Limit: 1000MSMemory Limit: 65536KTotal Submissions: 13247Accepted: 4655DescriptionGiven three strings, you are to determine whether the third string can be formed by combining the characters in the first two strings. The first two strings can be mixed arbitrarily, but each must stay in it 阅读全文

posted @ 2012-09-05 21:02 yumao 阅读(177) 评论(0) 推荐(0) 编辑

DFS poj 3009

摘要: Curling 2.0Time Limit: 1000MSMemory Limit: 65536KTotal Submissions: 7141Accepted: 2991DescriptionOn Planet MM-21, after their Olympic games this year, curling is getting popular. But the rules are somewhat different from ours. The game is played on an ice game board on which a square mesh is marked. 阅读全文

posted @ 2012-09-05 20:50 yumao 阅读(170) 评论(0) 推荐(0) 编辑

导航