HDU 4055:Number String(DP计数)】的更多相关文章

题意: 给你一个含n个字符的字符串,字符为'D'时表示小于号,字符为“I”时表示大于号,字符为“?”时表示大小于都可以.比如排列 {3, 1, 2, 7, 4, 6, 5} 表示为字符串 DIIDID.任务是计算所有能产生给定字符串的序列数量,每个序列含n+1个数字,分别为1-n+1,即从1开始且不重复. 思路:DP计数.如下步骤 1)将规模n降低,使得对于每个i (1<=i<=n)都可以依靠i-1的结果来计算.最小规模为1个符号,决定两个数字的序列. 2)考虑对于具有i个数字的序列(值从1-…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4055 Number String Time Limit: 10000/5000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others) 问题描述 The signature of a permutation is a string that is computed as follows: for each pair of consecut…
Number String Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1016    Accepted Submission(s): 440 Problem Description The signature of a permutation is a string that is computed as follows: fo…
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…
Number String http://acm.hdu.edu.cn/showproblem.php?pid=4055 Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description The signature of a permutation is a string that is computed as follows: for each pai…
题意:由数字1到n组成的所有排列中,问满足题目所给的n-1个字符的排列有多少个,如果第i字符是‘I’表示排列中的第i-1个数是小于第i个数的. 如果是‘D’,则反之. 析:dp[i][j] 表示前 i 个数以 j 结尾有多少个,然后如果是 I ,那么就好,就是 i-1 中的前j-1项和,如果是 D,那就更好玩了,我们看这样一个性质,奇妙! 假设你有一个排列是 1 3 4 ,然后下一个数是 2,那么怎么放呢,我们把 排列中每一个大于等于 2的都加1,并不会影响这个排列,然后再把这个2放上, 因为我…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4055 题意: 给你一个由'I', 'D', '?'组成的字符串,长度为n,代表了一个1~n+1的排列中(数字不重复),相邻数字的增长趋势.('I'为增,'D'为减,'?'为未知) 问你符合条件的数列有多少种. 题解: 表示状态: dp[i][j] = combinations 表示长度为i的排列(由1~i组成),末尾为j,这样的排列的个数 找出答案: ans = ∑ dp[n][1 to n] 如何…
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…
给一个只含‘I','D','?'三种字符的字符串,I表示当前数字大于前面的数字,D表示当前的数字小于前面一位的数字,?表示当前位既可以小于又可以大于. 问1~n的排列中有多少个满足该字符串. http://blog.csdn.net/shiqi_614/article/details/7983298 http://www.cnblogs.com/kuangbin/archive/2012/10/04/2711330.html http://blog.csdn.net/cc_again/artic…
HDU 4054 Number String 思路: 状态:dp[i][j]表示以j结尾i的排列 状态转移: 如果s[i - 1]是' I ',那么dp[i][j] = dp[i-1][j-1] + dp[i-1][j-2] + .. + dp[i-1][1] 如果s[i - 1]是‘D’,那么dp[i][j] = dp[i-1][j] + dp[i-1][j+1] + ... + dp[i-1][i] 用前缀和处理出sum[i][j]就不用dp[i][j]了 代码: #include<bits…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6146 题意:~ 解法:原题..http://blog.csdn.net/y990041769/article/details/21243895 #include <bits/stdc++.h> using namespace std; typedef long long LL; const int maxn = 10010; LL a[maxn], b[maxn]; const LL mod =…
题意: 国王的士兵有n个,每个人的身高都不同,国王要将他们排列,必须一高一矮间隔进行,即其中的一个人必须同时高于(或低于)左边和右边.问可能的排列数.例子有1千个,但是最多只算到20个士兵,并且20个的情况的答案已给出. 思路:是此题HDU 4055 Number String(DP计数) 的简单版,所以看此题解就行了.数量较小,可以预先算出来.要同时考虑 <><>和><><这样的两种情况. #include <iostream> #includ…
题目链接: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].…
Matt loves letter L.A point set P is (a, b)-L if and only if there exists x, y satisfying:P = {(x, y), (x + 1, y), . . . , (x + a, y), (x, y + 1), . . . , (x, y + b)}(a, b ≥ 1)A point set Q is good if and only if Q is an (a, b)-L set and gcd(a, b) =…
Number String 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4055 dp 定义状态:dp[i][j]为当strlen=i,数字结尾为j的方案数. 当为'I'时,dp[i][j]=∑dp[i-1][1...j-1];//若之前填过j,可以让前面j到i的数+1 当为'D'时,dp[i][j]=∑dp[i-1][j...i]; 当为'?'时,dp[i][j]=∑dp[i-1][1...i]. 于是我们有了O(n3)的算法: #includ…
Ring Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3180    Accepted Submission(s): 1033 Problem Description For the hope of a forever love, Steven is planning to send a ring to Jane with a rom…
hdu 4055: 一开始我想的递推方向想得很复杂,看了别人的博客后才醍醐灌顶: 参照他的思路和代码: #include<cstdio> #include<cstring> #include<algorithm> using namespace std; ; ; char s[N]; int dp[N][N], sum[N][N]; int main() { )) { memset(dp,,sizeof(dp)); // memset(sum,0,sizeof(sum)…
// 多校5 HDU5787 K-wolf Number 数位DP // dp[pos][a][b][c][d][f] 当前在pos,前四个数分别是a b c d // f 用作标记,当现在枚举的数小于之前的数时,就不用判断i与dig[pos]的大小 // 整体来说就,按位往后移动,每次添加后形成的数都小于之前的数,并且相邻k位不一样,一直深搜到cnt位 // http://blog.csdn.net/weizhuwyzc000/article/details/52097690 // #prag…
题目链接:  HDU 1011 树形背包(DP) Starship Troopers 题意:  地图中有一些房间, 每个房间有一定的bugs和得到brains的可能性值, 一个人带领m支军队从入口(房间1)进入, 只有到达某个房间并且将bugs全部杀死, 才能得到相应该的值. 问最多能获得多少可能性值. PS  1). 一支军队能杀死 20 bugs,  当一支军队发生战争之后就不能再到其它地方去了 2) . 不能走回头路 分析:  [树形背包] 用dp[i][j]表示到达房间 i 的军队数为…
Number String Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1027 Accepted Submission(s): 448 Problem Description The signature of a permutation is a string that is computed as follows: for each…
Number string number Js只有一种数字类型(包括整型,浮点型) 极大或极小的可用科学计数法来表示.(7.7123e+1) 所有js数字均为64位 Js所有的数字都存储为浮点型 小数的最大位数是17位 0开头的为八进制 0x开头的为16进制 console.log(Number.MAX_VALUE); 最大值 console.log(Number.MIN_VALUE);最小值 console.log(Number.NEGATIVE_INFINITY);极大值 console.l…
题目链接: https://codeforces.com/contest/166/problem/E 题目: 题意: 给你一个三菱锥,初始时你在D点,然后你每次可以往相邻的顶点移动,问你第n步回到D点的方案数. 思路: 打表找规律得到的序列是0,3,6,21,60,183,546,1641,4920,14763,通过肉眼看或者oeis可以得到规律为. dp计数:dp[i][j]表示在第i步时站在位置j的方案数,j的取值为[0,3],分别表示D,A,B,C点,转移方程肯定是从其他三个点转移. 代码…
链接:HDU-4055:Number String 题意:给你一个字符串s,s[i] = 'D'表示排列中a[i] > a[i+1],s[i] = 'I'表示排列中a[i] < a[i+1],s[i]  = '?' 表示无限制. 题解:dp[i][j]表示前i个满足字符串条件的结尾为j的 i 的排列. 如果s[i - 1]是' I ',那么dp[i][j] = dp[i-1][1] + dp[i-1][2] + .. + dp[i-1][j-1] 如果s[i - 1]是‘D’,那么dp[i][…
HDOJ(HDU).1058 Humble Numbers (DP) 点我挑战题目 题意分析 水 代码总览 /* Title:HDOJ.1058 Author:pengwill Date:2017-2-15 */ #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #define nmax 6000 #define min(a,b) (a<b?a:b…
总是不能正确的将一个大问题变成子问题,而且又找不到状态转移方程. 直接导致这题想了5个小时最后还是无果... 谨记! Number String Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1136    Accepted Submission(s): 503 Problem Description The signature of…
Bomb HDU - 3555 (数位DP) The counter-terrorists found a time bomb in the dust. But this time the terrorists improve on the time bomb. The number sequence of the time bomb counts from 1 to N. If the current number sequence includes the sub-sequence "49&…
HDU 1711 Number Sequence(数列) Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) [Description] [题目描述] Given two sequences of numbers : a[1], a[2], ...... , a[N], and b[1], b[2], ...... , b[M] (1 <= M <= 10000, 1 <= N…
HDU 1005 Number Sequence(数列) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) [Description] [题目描述] A number sequence is defined as follows: f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7. Given A, B, an…
[root@wx03 ~]# cat a17.pl use JSON qw/encode_json decode_json/ ; use Encode; my $data = [ { 'name' => 'Ken' , 'age' => 19 }, { 'name' => '测试' , 'age' => 25 } ]; ##解json格式 my $array = decode_json ( $data ); print "1111111111\n"; print…
题目大意:给定一个有 N 个数的序列,求其最长下降子序列的长度,并求出有多少种不同的最长下降子序列.(子序列各项数值相同视为同一种) update at 2019.4.3 题解:求最长下降子序列本身并不难,是一道非常经典的线性dp问题,关键在于dp计数部分.这道题跟一般的状态转移计数不同,这里并不是按照状态去计数,对于状态来说不会有重复的情况发生. 考虑何时会产生答案重叠.对于序列中两个值相同的元素 \(a_i,a_j,(j<i)\),到 i 之前的序列被这两个相同的元素分成了两部分,即:小于…