uva 702 The Vindictive Coach (DP)
来源:互联网 发布:ed hardy正品网络购买 编辑:程序博客网 时间:2024/06/05 09:01
Problem A : The Vindictive Coach
From:UVA, 702
The Vindictive Coach
The coach of a football team, after suffering for years the adverse comments of the media about his tactics, decides to take his revenge by presenting his players in a line-up in such a way that the TV cameras would be compelled to zigzag in a ridiculous bobbing motion, by alternating taller and shorter players. However, the team captain objects that he must be the first of the line by protocolary reasons,and that he wants to be seen in the best possible light: that is, he should not have a taller colleague nest to him unless there is no alternative (everyone else is taller than him). Even in this case, the height difference should be as small as possible, while maintaining the zigzag arrangement of the line.
With this condition the coach addresses an expert in computation (i.e. you) to help him find the number of different alignments he may make, knowing that all players have a different height. They are always numbered by stature starting by 1 as the shortest one. Of course the number of players may be arbitrary, provided it does not exceed 22.
Input
It is a set of lines, each of which contains two positive integers N andm separated by a blank space. represents the number of players in the line-up andm the captain's number, who as told is always the first of the line.
Output
For every line of the input a line with positive integer indicating the number of possible alignments under the above conditions.
Sample Input
3 13 34 1
Sample Output
111
#include <iostream>#include <cstdio>using namespace std;const int maxn = 30;long long int dp[maxn][maxn][2];int N , m;void initial(){for(int i = 0;i < maxn;i++){for(int j = 0;j < maxn;j++){dp[i][j][0] = -1;dp[i][j][1] = -1;}}}long long DP(int h , int l , int k){if(h+l == 0){return 1;}if((h <= 0 && k == 1) || (l <= 0 && k == 0)){return 0;}if(dp[h][l][k] != -1){return dp[h][l][k];}long long int ans = 0;if(k == 0){for(int i = 1;i <= l;i++){ans += DP(h+i-1 , l-i , 1);}}else{for(int i = 1;i <= h;i++){ans += DP(h-i , l+i-1 , 0);}}dp[h][l][k] = ans;return ans;}void computing(){if(N <= 2){cout << 1 << endl;return;}if(m == 1){cout << DP(N-3 , 1 , 0) << endl;}else{cout << DP(N-m , m-1 , 0) << endl;}}int main(){while(cin >> N >> m){initial();computing();}return 0;}
- uva 702 The Vindictive Coach (DP)
- LightOJ 1173 The Vindictive Coach (DP 计数)
- LightOJ 1173 The Vindictive Coach (DP)
- lightoj 1173 - The Vindictive Coach 计数类DP
- LightOJ 1173 The Vindictive Coach(DP计数)
- Pay the Price+uva+dp
- UVA 12099 The Bookcase(dp)
- UVA 590 - Always on the run (dp)
- UVA 10564 - Paths through the Hourglass (dp)
- UVA 10066 The Twin Towers(dp + LCS)
- UVA 590 Always on the run(dp)
- uva 10564 - Paths through the Hourglass(dp)
- UVA 10564Paths through the Hourglass(dp)
- uva 10254 - The Priest Mathematician(dp)
- UVa 10066 The Twin Towers (DP&LCS)
- Uva 6436 - The Busiest City 树形DP
- uva 11471 Arrange the Tiles (DP)
- UVA 11077 Find the Permutations(置换+dp)
- 收集一些top软件公司经典算法面试题
- 大数据的处理(Sqlserver2008)
- 动态加载指令问题
- Unicode编码,以及实现方式UTF8的实现方式
- 单独渲染出来像瀑布流这样的效果
- uva 702 The Vindictive Coach (DP)
- 构建自己的AngularJS,第一部分:Scope和Digest
- iOS Dev (21) 用 AVPlayer 播放一个本地音频文件
- sqlplus与sqlplusw
- java nio为什么是通道(三): 网络Channel
- [LeetCode] Valid Sudoku
- AngularJS:何时应该使用Directive、Controller、Service?
- ReadProcessMemory与WriteProcessMemory用例分析
- 多层嵌套的拖动排序组件