sdut 2840 Best string Orz~ (dp)】的更多相关文章

题目 题意:有n1个o, n2个r, n3个z, n4个~, 求有多少种组合使 组合出来的字符串的任意前缀都满足 o的个数>=r的个数, r的个数>=z的个数 …………………… 思路:递推,枚举用四重循环控制orz~的个数符合题意, 然后当前个数的orz~等于之前orz~分别少一个推过来的,所以相加上, 注意之前可能orz~的某一个没有. 下面的代码是看了标程之后写出来的. #include <iostream> #include <cstdio> #include &…
1048. Longest String Chain https://leetcode.com/problems/longest-string-chain/ Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecess…
题目: http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1305 这个题就是一个类似公共子串的dp,但是加了权值,其实还是很简单. 当匹配时相似程度是5,不匹配是-4,添加空隙是-7.那么dp[i][j]的值就来自于三个方式: 1.在s2[j]后添加空隙,那么相似程度就是dp[i][j-1] - 7 2.在s1[i]后添加空隙,那么相似程度就是dp[i-1][j] - 7 3.直接拿s1[i]和s2[j…
Count the string Problem Description It is well known that AekdyCoin is good at string problems as well as number theory problems. When given a string s, we can write down all the non-empty prefixes of this string. For example:s: "abab"The prefi…
题目链接. #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <string> using namespace std; +; char s1[maxn], s2[maxn], s3[maxn]; int dp1[maxn][maxn], dp2[maxn][maxn]; ], que2[maxn][]; void max_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…
Problem F - String Partition                                                                                                                     Time limit: 3.000 seconds John was absurdly busy for preparing a programming contest recently. He wanted…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3336 很容易想到用kmp 这里是next数组的应用 定义dp[i]表示以s[i]结尾的前缀的总数 那么dp[i]=dp[next[i]]+1; 代码: #include<stdio.h> #include<string.h> ; ; int dp[MAXN]; char str[MAXN]; int next[MAXN]; void getNext(char *p) { int j,k…
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…
Implement regular expression matching with support for '.' and '*'. '.' Matches any single character. '*' Matches zero or more of the preceding element. The matching should cover the entire input string (not partial). The function prototype should be…