uva 10721 Bar Codes (DP)
2014-01-04 18:21
344 查看
Problem D | Bar Codes |
Time Limit | 1 Second |
extend over 1+2+3+1=7 units.
Figure 1: Bar-code over 7 units with 4 bars
In general, the bar code BC(n,k,m) is the set of all symbols with k bars that together extend over exactlyn units, each bar being at most m units
wide. For instance, the symbol in Figure 1 belongs to BC(7,4,3) but not to BC(7,4,2). Figure 2 shows all 16 symbols in BC(7,4,3). Each `1' represents a dark unit, each `0' a light unit.
0: 1000100 | 4: 1001110 | 8: 1100100 | 12: 1101110
1: 1000110 | 5: 1011000 | 9: 1100110 | 13: 1110010
2: 1001000 | 6: 1011100 | 10: 1101000 | 14: 1110100
3: 1001100 | 7: 1100010 | 11: 1101100 | 15: 1110110
Figure 2: All symbols of BC(7,4,3)
Input
Each input will contain three positive integers n, k, and m (1 ≤ n, k, m ≤ 50).
Output
For each input print the total number of symbols in BC(n,k,m). Output will fit in 64-bit signed integer.
Sample Input | Output for Sample Input |
7 4 3 7 4 2 | 16 4 |
#include <iostream> #include <cstdio> using namespace std; const int maxn = 60; long long int dp[maxn][maxn][maxn][2]; int n , k , m; void initial(){ for(int i = 0;i < maxn;i++){ for(int j = 0;j < maxn;j++){ for(int l = 0;l < maxn;l++){ dp[i][j][l][0] = 0; dp[i][j][l][1] = 0; } } } } void computing(){ dp[1][1][1][1] = 1; for(int i = 1;i < n;i++){ for(int j = 1;j <= m;j++){ for(int l = 1;l <= k;l++){ if(dp[i][j][l][0] != 0){ dp[i+1][j+1][l][0] += dp[i][j][l][0]; dp[i+1][1][l+1][1] += dp[i][j][l][0]; } if(dp[i][j][l][1] != 0){ dp[i+1][j+1][l][1] += dp[i][j][l][1]; dp[i+1][1][l+1][0] += dp[i][j][l][1]; } } } } long long int sum = 0; for(int i = 1;i <= m;i++){ sum += dp [i][k][0]; sum += dp [i][k][1]; } cout << sum << endl; } int main(){ while(cin >> n >> k >> m){ initial(); computing(); } return 0; }
[align=center][/align]
相关文章推荐
- nodejs的安装
- 《精通PKI网络安全认证技术与编程实现》 读书笔记二
- 本土回忆! 即使你走的再远,也不能忘了让你生长的老家文化~
- 数据结构 - 图
- vmclone 问题
- C#判断文件格式
- OpenGL Perspective Projection Matrix
- C++调用C函数
- ios专题 -内存管理 研究
- [整理]VIM使用指南
- 乐一下
- IOS UIView子类UIScrollView
- nagios使用第三方邮箱发送报警
- XCODE4.6从零开始添加视图
- 我的20132014
- SQL:Oracle中检测某一字段中是否含有中文
- 误删QQ空间里的照片可以恢复了?
- 关闭Linux系统的mDNS服务
- android ListView美化-->几个比较特别的属性
- Asp.net MVC验证哪些事(3)-- Remote验证及其改进(附源码)