hdu 4055 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…
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…
题目链接: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].…
题意:由数字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放上, 因为我…
题目: 题意: 给你一个字符串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个元素…
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…
题目链接: 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 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…