All of you know a bit or two about hashing. It involves mapping an element into a numerical value using some mathematical function. In this problem we will consider a very ‘simple minded hashing’. It involves assigning numerical 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.

  1. abg
  2. acf
  3. ade
  4. 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 signed integers.
Sample Input
3 10
2 3
0 0
Sample Output
Case 1: 4
Case 2: 1

问题链接:UVA10912 Simple Minded Hashing
问题简述:(略)
问题分析:动态规划问题,不解释。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* UVA10912 Simple Minded Hashing */#include <bits/stdc++.h>using namespace std;const int M = 26;
const int N = 10000;
int dp[M + 1][M + 1][N + 1], sum[M + 1][N + 1];void init()
{memset(dp, 0, sizeof dp);memset(sum, 0, sizeof sum);dp[0][0][0] = 1;for (int i = 1; i <= M; i++)for (int k = 1; k <= i * M; k ++)for (int j = 1; j <= min(k, M); j++) {for (int m = 0; m < j; m++)dp[i][j][k] += dp[i - 1][m][k - j];sum[i][k] += dp[i][j][k];}
}int main()
{init();int l, s, caseno = 0;while (scanf("%d%d", &l, &s) == 2 && (l || s))printf("Case %d: %d\n", ++caseno, sum[min(l, M)][s]);return 0;
}

UVA10912 Simple Minded Hashing【DP】相关推荐

  1. 【DP】【期望】$P1850$换教室

    [DP][期望]\(P1850\)换教室 链接 题目描述 有 \(2n\) 节课程安排在$ n$ 个时间段上.在第 \(i\)(\(1 \leq i \leq n\))个时间段上,两节内容相同的课程同 ...

  2. Bailian2760 数字三角形【DP】

    2760:数字三角形 描述 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5 (图1) 图1给出了一个数字三角形.从三角形的顶部到底部有很多条不同的路径.对于每条路径,把路径上面的数加起来可 ...

  3. NUC1131 Triangle【DP】

    Triangle 时间限制: 1000ms 内存限制: 65536KB 通过次数: 1总提交次数: 1 问题描述 图1表示一个数字三角形. 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5 ...

  4. LeetCode:完全平方数【279】【DP】

    LeetCode:完全平方数[279][DP] 题目描述 给定正整数 n,找到若干个完全平方数(比如 1, 4, 9, 16, ...)使得它们的和等于 n.你需要让组成和的完全平方数的个数最少. 示 ...

  5. 【DP】序列 题解

    [DP]序列 题解 序列 题目 一个长度为kkk的整数序列bbb 1,bbb 2,-,bkbkbk(1≤bbb 1≤bbb 2≤-≤bkbkbk≤NNN)称为"好序列"当且仅当后一 ...

  6. poj 2411 Mondriaan#39;s Dream 【dp】

    题目:poj 2411 Mondriaan's Dream 题意:给出一个n*m的矩阵,让你用1*2的矩阵铺满,然后问你最多由多少种不同的方案. 分析:这是一个比較经典的题目.网上各种牛B写法一大堆. ...

  7. BestCoder冠军赛 - 1005 Game 【DP】

    [题意] 给出一个set,set中有几个数. 现在给出n个人,环成一圈搞约瑟夫... 开始时从第1号报数,每次从set中随机选出一个数s,等报数到s后,报s的人出圈,其他人继续报数. 最后只剩1人时, ...

  8. 【9.22校内测试】【可持久化并查集(主席树实现)】【DP】【点双联通分量/割点】...

    1 build 1.1 Description 从前有一个王国,里面有n 座城市,一开始两两不连通.现在国王将进行m 次命令,命令可 能有两种,一种是在u 和v 之间修建道路,另一种是询问在第u 次命 ...

  9. zzuliOJ 1894: 985的方格难题 【dp】

    1894: 985的方格难题 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 369  Solved: 75 Description 985走入了一个n ...

最新文章

  1. ant java build_Ant--基于java的build工具
  2. 类似飞秋的局域网软件_内网视频会议软件系统
  3. @import和@class的区别
  4. Visual Studio 中Debug模式和Release模式的区别
  5. 控制反转(ioc)和 面向切面(AOP)
  6. Python之删除字符串中不需要的字符
  7. MYSQL中最基础的的聚合函数(重点!)
  8. 全面解析Linux 内核 3.10.x - 如何开始
  9. 加州“电力十足 ” iPhone12加速贬值成全“十三香”
  10. php7 viewmodel,ViewModel浅析
  11. 基于JAVA+SpringMVC+Mybatis+MYSQL的课堂考勤系统
  12. 一个优秀的公司如何才能成为一个卓越的公司?
  13. 拟牛顿法/Quasi-Newton,DFP算法/Davidon-Fletcher-Powell,及BFGS算法/Broyden-Fletcher-Goldfarb-Shanno...
  14. python画50个图-python 实现在一张图中绘制一个小的子图方法
  15. java程序员中英文简历_2017java程序员英文简历范文
  16. 基于Flink建设流批一体实时数仓
  17. 第八届中国信息安全大会在京召开
  18. python—networkx:画随机几何图,找出中心节点并按路径长度染色
  19. Springboot错误页面和错误信息定制
  20. Maven命令行 打包

热门文章

  1. 二分图带权最大匹配费用流_简单理解二分图与匈牙利算法
  2. 2020-01-14 英文资料How to Set Up Intel® Ethernet Flow Director
  3. WebConfig主要节点配置总结
  4. vconsole在手机真机模拟器上显示console控制台
  5. mysql econnreset_javascript - 节点Js mysql(和mysql2)ECONNRESET - 堆栈内存溢出
  6. portal认证 只能重定向80和443请求_华为防火墙内置Portal认证报文交互
  7. jqGrid中时间控件input的值赋给点开后的laydate控件
  8. 深入了解vue中slot和slot-scope
  9. html禁止页面动画,如何在页面加载时阻止CSS动画?
  10. python实现qq登录_python实现QQ批量登录功能