Number String(DP)】的更多相关文章

Problem Description The signature of a permutation is a string that is computed as follows: for each pair of consecutive elements of the permutation, write down the letter 'I' (increasing) if the second element is greater than the first one, otherwis…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4055 思路:dp[i][j]表示处理前i个字符以j结尾可能的序列数. 当a[i]=='I'时,dp[i][j]=sum(dp[i-1][k]),(1<=k<=j-1), 可进一步化为dp[i][j-1]+dp[i-1][j-1]. 当a[i]=='D'时,dp[i][j]=sum(dp[i-1][k]),(j<=k<=i-1),可进一步化为dp[i][j+1]+dp[i-1][j].…
题目: 题意: 给你一个字符串s,s[i] = 'D'表示排列中a[i] > a[i+1],s[i] = 'I'表示排列中a[i] < a[i+1]. 比如排列 {3, 1, 2, 7, 4, 6, 5} 表示为字符串 DIIDID. 解题思路: 用一个二维数组dp[i][j]表示:长度为 i ,以数字 j 结尾的数字串的排列有多少种,dp[0][1]=1是确定了的. 但是在状态转移的时候,我们不得不考虑前面选了什么,也就是状态的设定是有后效性的, 所以考虑给状态再添一层含义:必须选前i个元素…
Number String Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1935    Accepted Submission(s): 931 Problem Description The signature of a permutation is a string that is computed as follows: for…
题意:构造一个由a组成的串,如果插入或删除一个a,花费时间x,如果使当前串长度加倍,花费时间y,问要构造一个长度为n的串,最少花费多长时间. 分析:dp[i]---构造长度为i的串需要花费的最短时间. 1.构造长度为1的串,只能插入,dp[1] = x. 2.当前串的长度i为偶数,可以 (1)长度为i/2的串加倍:dp[i / 2] + y (2)长度为i-1的串插入一个a:dp[i - 1] + x 3.当前串的长度i为奇数,可以 (1)长度为i/2的串加倍,再加上一个a:dp[i / 2]…
http://acm.hdu.edu.cn/showproblem.php?pid=4055 题意:给一个仅包含‘I','D','?'的字符串,’I'表示前面的数字比后面的数字要小(Increase升序),'D'表示前面的数字比前面的数字要大(Decrease降序),'?'表示有可能是'I'也有可能是'D',长度为n的字符串就有n+1个数字,在这n+1个数字里面,问符合给出的字符串的条件的序列数有多少种. 思路:dp[i][j]的定义:i表示当前枚举到第i个字符(即长度为i+1的时候的序列),j…
Problem Description Given three strings a, b and c , your mission is to check whether c is the combine string of a and b .A string c is said to be the combine string of a and b if and only if c can be broken into two subsequences, when you read them…
Generate a String 题目链接: http://codeforces.com/contest/710/problem/E Description zscoder wants to generate an input file for some programming competition problem. His input is a string consisting of n letters 'a'. He is too lazy to write a generator s…
Leetcode之动态规划(DP)专题-264. 丑数 II(Ugly Number II) 编写一个程序,找出第 n 个丑数. 丑数就是只包含质因数 2, 3, 5 的正整数. 示例: 输入: n = 10 输出: 12 解释: 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 是前 10 个丑数. 说明: 1 是丑数. n 不超过1690. dp含义: dp[i]表示第i-1个丑数. class Solution { public int nthUglyNumber(int n)…
LightOJ 1033  Generating Palindromes(dp) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730#problem/A 题目: Description By definition palindrome is a string which is not changed when reversed. "MADAM" is a nice example of palindrome.…