HDU4055 - number string(DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4055
#include<cstdio>
#include<cstring>
using namespace std;
const int N = 1e3 + 5;
const int mod = 1e9 + 7;
char a[N];
int dp[N][N];
int main()
{
while(~scanf("%s",a+2))
{
memset(dp,0,sizeof(dp));
int len = strlen(a+2) + 1;
dp[1][1] = 1;
for(int i = 2 ;i <= len ;i++)
{
if(a[i] == 'I')
{
for(int j = 2 ;j <= i ;j++)
dp[i][j] = (dp[i][j-1] + dp[i-1][j-1]) % mod;
}
else if(a[i] == 'D')
{
for(int j = i-1 ;j >= 1 ;j--)
dp[i][j] = (dp[i][j+1] + dp[i-1][j]) % mod;
}
else
{
int sum = 0;
for(int j = 1 ;j <= i-1 ;j++)
sum = (sum + dp[i-1][j]) % mod;
for(int j = 1 ;j <= i ;j++)
dp[i][j] = sum;
}
}
int ans = 0;
for(int i = 1 ;i <= len ;i++)
ans = (ans + dp[len][i]) % mod;
printf("%d\n",ans);
}
return 0;
}
HDU4055 - number string(DP)的更多相关文章
- hdu 4055 Number String(dp)
Problem Description The signature of a permutation is a string that is computed as follows: for each ...
- Number String(DP)
题目: 题意: 给你一个字符串s,s[i] = 'D'表示排列中a[i] > a[i+1],s[i] = 'I'表示排列中a[i] < a[i+1]. 比如排列 {3, 1, 2, 7, ...
- hdu 4055 Number String (基础dp)
Number String Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- CodeForces - 710E Generate a String (dp)
题意:构造一个由a组成的串,如果插入或删除一个a,花费时间x,如果使当前串长度加倍,花费时间y,问要构造一个长度为n的串,最少花费多长时间. 分析:dp[i]---构造长度为i的串需要花费的最短时间. ...
- HDU 4055:Number String(DP计数)
http://acm.hdu.edu.cn/showproblem.php?pid=4055 题意:给一个仅包含‘I','D','?'的字符串,’I'表示前面的数字比后面的数字要小(Increase升 ...
- hdu5707-Combine String(DP)
Problem Description Given three strings a, b and c , your mission is to check whether c is the combi ...
- Educational Codeforces Round 16 E. Generate a String (DP)
Generate a String 题目链接: http://codeforces.com/contest/710/problem/E Description zscoder wants to gen ...
- Leetcode之动态规划(DP)专题-264. 丑数 II(Ugly Number II)
Leetcode之动态规划(DP)专题-264. 丑数 II(Ugly Number II) 编写一个程序,找出第 n 个丑数. 丑数就是只包含质因数 2, 3, 5 的正整数. 示例: 输入: n ...
- LightOJ 1033 Generating Palindromes(dp)
LightOJ 1033 Generating Palindromes(dp) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...
随机推荐
- nyoj------79拦截导弹
拦截导弹 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 某国为了防御敌国的导弹袭击,发展中一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到 ...
- Valid Palindrome [LeetCode]
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- linux安装.run
chmod +x ./framework-3.6.0-linux-full.runsudo ./framework-3.6.0-linux-full.run
- 多条查询sql语句返回多表数据集
+ + "';SELECT ProductID,ProductTitle,ProductName,SalePrice,ListingPrice,MainPicture,SaledItemCo ...
- 批次更新BAPI_OBJCL_CHANGE
FORM frm_edit_batch TABLES pt_field STRUCTURE dfies USING ps_batch TYPE ty_batch CHANGING ps_rturn T ...
- jdk版本比较
JDK各个版本的新特性 对于很多刚接触java语言的初学者来说,要了解一门语言,最好的方式就是要能从基础的版本进行了解,升级的过程,以及升级的新特性,这样才能循序渐进的学好一门语言.今天先为大家介绍一 ...
- LevelDb简单介绍和原理——本质:类似nedb,插入数据文件不断增长(快照),再通过删除老数据做更新
转自:http://www.cnblogs.com/haippy/archive/2011/12/04/2276064.html 有时间再好好看下整个文章! 说起LevelDb也许您不清楚,但是如果作 ...
- 数组作为hash元素的时候如何push
####################################################################### # Copyright (C) 2015 All rig ...
- S1:new操作符
function Shape(type){ this.type = type || "rect"; this.calc = function(){ return "cal ...
- C char** 的一点儿理解
理解是就是char** 相当于字符串数组,我以往纠结于该用 **arr还是*arr还是 (*arr),还是(**arr): 对于**arr而言:*arr代表数组的最开头,也就是第一个字串的内容.**a ...