uva 10912 Simple Minded Hashing (DP)
2014-01-06 12:29
465 查看
4th IIUC Inter-University Programming Contest, 2005 | |
H | Simple Minded Hashing |
Input: standard input Output: standard output | |
Problemsetter: Sohel Hafiz |
value to the alphabets and summing these values of the characters.
For example, the string “acm” is mapped to 1 + 3 + 13 = 17. Unfortunately, this method does not give one-to-one mapping. The string “adl” also maps to 17 (1 + 4 + 12). This is called collision.
In this problem you will have to find the number of strings of length
L, which maps to an integer S, using the above hash function. You have to consider strings that have only lowercase letters in strictly ascending order.
Suppose L = 3 and S = 10, there are 4 such strings.
abg
acf
ade
bce
agb also produces 10 but the letters are not strictly in ascending order.
bh also produces 10 but it has 2 letters.
Input
There will be several cases. Each case consists of 2 integers L and S.
(0 < L, S < 10000). Input is terminated with 2 zeros.
Output
For each case, output Case #: where # is replaced by case number. Then output the result. Follow the sample for exact format. The result will fit in 32 bit signed integers.
Sample Input | Output for Sample Input |
3 10 2 3 0 0 | Case 1: 4 Case 2: 1 |
#include <iostream> #include <cstdio> using namespace std; const int maxn = 10010; int L , S; int dp[maxn][30]; void initial(){ for(int i = 0;i < maxn;i++){ for(int j = 0;j < 30;j++){ dp[i][j] = 0; } } } void computing(){ dp[0][0] = 1; for(int i = 1;i <= 26;i++){ for(int j = i-1;j >= 0;j--){ for(int k = maxn-1-i;k >= 0;k--){ dp[k+i][j+1] += dp[k][j]; } } } } int main(){ int t = 1; initial(); computing(); while(cin >>L >> S && (L||S)){ printf("Case %d: " , t++); if(L > 26){ cout << 0 << endl; }else{ cout << dp[S][L] << endl; } } return 0; }
相关文章推荐
- UVA10912 - Simple Minded Hashing(dp)
- Uva 10912 Simple Minded Hashing (计数DP)
- UVa - 10912 - Simple Minded Hashing-(dp)
- UVA 10912 Simple Minded Hashing
- UVa 10912 - Simple Minded Hashing
- uva 10912 - Simple Minded Hashing(计数)
- UVA 10912 Simple Minded Hashing
- 10912 - Simple Minded Hashing (dp)
- UVA 10912 Simple Minded Hashing
- 10912 - Simple Minded Hashing
- UVA - 10003 Cutting Sticks(dp和记忆化搜索两种解法)
- UVALive - 6952 (隔板dp)
- UVA 562 Dividing coins(DP:01背包)
- uva11400--Lighting System Design DP
- uva 327 Evaluating Simple C Expressions 简易C表达式计算 stl模拟
- UVa 10404 Bachet's Game(DP)
- uvalive-6190(二分+dp验证)
- dp uva10003
- uva 327 - Evaluating Simple C Expressions
- UVA1630 Folding 区间DP