HDU 5078 Revenge of LIS II(dp LIS)】的更多相关文章

Problem Description In computer science, the longest increasing subsequence problem is to find a subsequence of a given sequence in which the subsequence's elements are in sorted order, lowest to highest, and in which the subsequence is as long as po…
#include <stdio.h> #include <string.h> #define MAX 1009 int main() { },b[MAX]={}; ,z=,r=,k=; char *p=NULL; scanf("%d",&n); <n&&n< ){ ;i<n;i++){ j=; z=; r=; scanf("%s",a); scanf("%s",b); printf…
题意:给定一个长度为n的序列,让你求一个和最大递增序列. 析:一看,是不是很像LIS啊,这基本就是一样的,只不过改一下而已,d(i)表示前i个数中,最大的和并且是递增的, 如果 d(j) + a[i] > d(i)  d(i) = d(j) + a[i] (这是保证和最大),那么怎么是递增呢?很简单嘛,和LIS一样 再加上a[i] > a[j],这不就OK了. 代码如下: #include <cstdio> #include <iostream> #include &l…
Rikka with Parenthesis II 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5831 Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them: Correct parenthe…
题目链接:http://poj.org/problem?id=1631 这个题题目有些难看懂hhh,但实质就是求LIS--longest increasing sequence. 以下介绍LIS的解法模板: 一.O(n^2)解法 用a数组存储数据,f[i]表示以a[i] 结尾的最长子序列的长度,这样max(f[i])就是所求结果. 代码如下: #include<cstdio> #include<algorithm> using namespace std; int n,p; ],f…
Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6191    Accepted Submission(s): 3664 Problem Description Now our hero finds the door to the BEelzebub feng5166. He o…
转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents    by---cxlove 题意:给出一个环,每个点是一个数字,取一个子串,使得拼接起来的数字是K的倍数. 由于K不大,暂且不考虑环的话,那么dp[i][j]表示以i结尾的,模K为j的有多少个子串. 那么sigma (dp[i][0])便是不考虑环的答案. 考虑环的话,不知道别人怎么写的,我感觉我的写法不是很复杂. 环和情况1 和n肯定是必选的,那么便是一个前缀为后缀,一个后…
经典的汉诺塔问题经常作为一个递归的经典例题存在.可能有人并不知道汉诺塔问题的典故.汉诺塔来源于印度传说的一个故事,上帝创造世界时作了三根金刚石柱子,在一根柱子上从下往上按大小顺序摞着64片黄金圆盘.上帝命令婆罗门把圆盘从下面开始按大小顺序重新摆放在另一根柱子上.并且规定,在小圆盘上不能放大圆盘,在三根柱子之间一回只能移动一个圆盘.有预言说,这件事完成时宇宙会在一瞬间闪电式毁灭.也有人相信婆罗门至今仍在一刻不停地搬动着圆盘.恩,当然这个传说并不可信,如今汉诺塔更多的是作为一个玩具存在.Gardon…
Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How many unique paths would there be? An obstacle and empty space is marked as 1 and 0 respectively in the grid. For example, There is one obstacle in the middl…
题目链接 Problem Description I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.   Input The first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T li…