HDU4972:A simple dynamic programming problem
来源:互联网 发布:mac os x 10.11懒人版 编辑:程序博客网 时间:2024/05/08 09:09
Problem Description
Dragon is watching NBA. He loves James and Miami Heat.
Here's an introduction of basketball game:http://en.wikipedia.org/wiki/Basketball. However the game in Dragon's version is much easier:
"There's two teams fight for the winner. The only way to gain scores is to throw the basketball into the basket. Each time after throwing into the basket, the score gained by the team is 1, 2 or 3. However due to the uncertain factors in the game, it’s hard to predict which team will get the next goal".
Dragon is a crazy fan of Miami Heat so that after each throw, he will write down the difference between two team's score regardless of which team keeping ahead. For example, if Heat's score is 15 and the opposite team's score is 20, Dragon will write down 5. On the contrary, if Heat has 20 points and the opposite team has 15 points, Dragon will still write down 5.
Several days after the game, Dragon finds out the paper with his record, but he forgets the result of the game. It's also fun to look though the differences without knowing who lead the game, for there are so many uncertain! Dragon loves uncertain, and he wants to know how many results could the game has gone?
Here's an introduction of basketball game:http://en.wikipedia.org/wiki/Basketball. However the game in Dragon's version is much easier:
"There's two teams fight for the winner. The only way to gain scores is to throw the basketball into the basket. Each time after throwing into the basket, the score gained by the team is 1, 2 or 3. However due to the uncertain factors in the game, it’s hard to predict which team will get the next goal".
Dragon is a crazy fan of Miami Heat so that after each throw, he will write down the difference between two team's score regardless of which team keeping ahead. For example, if Heat's score is 15 and the opposite team's score is 20, Dragon will write down 5. On the contrary, if Heat has 20 points and the opposite team has 15 points, Dragon will still write down 5.
Several days after the game, Dragon finds out the paper with his record, but he forgets the result of the game. It's also fun to look though the differences without knowing who lead the game, for there are so many uncertain! Dragon loves uncertain, and he wants to know how many results could the game has gone?
Input
The first line of input contains only one integer T, the number of test cases. Following T blocks, each block describe one test case.
For each test case, the first line contains only one integer N(N<=100000), which means the number of records on the paper. Then there comes a line with N integers (a1, a2, a3, ... , an). ai means the number of i-th record.
For each test case, the first line contains only one integer N(N<=100000), which means the number of records on the paper. Then there comes a line with N integers (a1, a2, a3, ... , an). ai means the number of i-th record.
Output
Each output should occupy one line. Each line should start with "Case #i: ", with i implying the case number. Then for each case just puts an integer, implying the number of result could the game has gone.
Sample Input
222 341 3 5 7
Sample Output
Case #1: 2Case #2: 2#include<cstdio>#include<algorithm>using namespace std;#define s(a) scanf("%d",&a)int t,c=1,n,a[100005],i,flag,ans;main(){ s(t); while(t--) { s(n); for(i=0,flag=1,ans=2; i<n; i++) s(a[i]); if(a[0]>3||a[0]==0) flag=0; if(flag) { for(i=1; i<n; i++) { if(a[i]-a[i-1]>3||a[i-1]-a[i]>3||(a[i]==a[i-1]&&a[i]!=1)) { flag=0; break; } if((a[i]==2&&a[i-1]==1)||(a[i]==1&&a[i-1]==2)) ans+=2; } if(a[n-1]==0) ans/=2; } printf("Case #%d: %d\n",c++,flag?ans:0); }}
0 0
- HDU4972:A simple dynamic programming problem
- HDU4972 A simple dynamic programming problem(规律)
- HDU4972 A simple dynamic programming problem(找规律)
- hdu4972 A simple dynamic programming problem(多校第十场1002)
- HDU 4972 A simple dynamic programming problem
- HDU 4972 A simple dynamic programming problem
- HDOJ 4972 A simple dynamic programming problem
- HDU-4972-A simple dynamic programming problem
- 【HDU】A simple dynamic programming problem
- hdu 4972 A simple dynamic programming problem 2014多校十
- 【杂题】 HDOJ 4972 A simple dynamic programming problem
- HDU 4972 A simple dynamic programming problem(推理)
- hdu 4972 A simple dynamic programming problem(高效)
- HDU 4972 A simple dynamic programming problem(找规律)
- hdu - 4972 - A simple dynamic programming problem(数学 + dp)
- 14多校 B-A simple dynamic programming problem
- hdu 4947 A simple dynamic programming problem(2014 Multi-University Training Contest 10)
- HDU 4972 A simple dynamic programming problem(数学思维题)
- How to untar a tar file or gzip-bz2 tar file
- cocos2dx 3.1.1 用tinyxml2.h解释xml (C++)
- jQuery中的AJAX的使用
- 什么是堆和栈,它们在哪儿?
- EasyUI Editable Tree
- HDU4972:A simple dynamic programming problem
- C#动态调用c++DLL的方法
- Contiki学习笔记之时钟初始化
- C/C++笔试题-主要考察C/C++语言基础概念、算法及编程
- 简单构建工具SBT
- TTL电平,CMOS电平,RS232电平
- WebView+ColorMatrix实现图片颜色的渐变处理,例如老照片的效果。
- Shell学习笔记一
- ios7.1以上企业级发布解决方案(二)