UVALive 4764 Bing it(dp)
来源:互联网 发布:南京行知实验中学排名 编辑:程序博客网 时间:2024/05/20 07:54
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2765点击打开链接
4764 - Bing it
Time limit: 3.000 secondsI guess most of you played cards on the trip to Harbin, but I’m sure you have never played thefollowing card game. This card game hasN rounds and 100000 types of cards numbered from 1 to100000. A new card will be opened when each round begins. You can “bing” this new card. And if thecard you last “bing” is the same with this new one, you will get 1 point. You can ”bing” only one card,but you can change it into a new one. For example, the order of the 4 cards is 1 3 4 3. You can “bing”1 in the rst round and change it into 3 in the second round. You get no point in the third round, butget 1 point in the last round. Additionally, there is a special card 999. If you “bing” it and it is openedagain, you will get 3 point.
Given the order ofN cards, tell me the maximum points you can get.Input
The input le will contain multiple test cases. Each test case will consist of two lines. The rst line ofeach test case contains one integerN (2≤ N≤ 100000). The second line of each test case contains asequence of nintegers, indicating the order of cards. A single line with the number ‘0’ marks the endof input; do not process this case.
Output
For each input test case, print the maximum points you can get.
Sample Input
2
11
5
1 999 3 3 9990
Sample Output
13
#include <iostream>#include <queue>#include <stdio.h>#include <stdlib.h>#include <stack>#include <limits>#include <string>#include <string.h>#include <vector>#include <set>#include <map>#include <algorithm>#include <math.h>#define maxn 100010using namespace std;set < int > point[100010];set < int > :: iterator it;int dp[maxn],a[maxn];int judge(int x,int y){ if(x==y&&x==999) return 3; else if(x==y) return 1; else return 0;}int main(){ int n=0; while(~scanf("%d",&n)&&n) { for(int i=0;i<=100000;i++) { point[i].clear(); dp[i]=0; a[i]=0; } for(int i=0;i<n;i++) { scanf("%d",&a[i]); point[a[i]].insert(i); } dp[0]=0; for(int i=1;i<n;i++) { dp[i]=max(dp[i-1]+judge(a[i],a[i-1]),dp[i]); for(it=point[a[i]].begin();it!=point[a[i]].end();it++) { if((*it)>=i-1) break; dp[i]=max(dp[(*it)]+judge(a[i],a[(*it)]),dp[i]); } } printf("%d\n",dp[n-1]); }}
- UVALive 4764 Bing it(dp)
- uvalive 4764 Bing it 基础dp
- UVALive 4764 Bing it
- Bing it UVALive
- Bing it UVALive
- Bing it(动态规划)dp
- Bing it
- DP->UVALive 4764
- UVALIVE 3516(DP)
- Bing It On Kattis
- Bing It On (Kattis
- UVALive 6430 Points(dp)
- UVALive 6848Fishing(dp)
- UVALive 7365 Composition (DP)
- UVALive 3305 Tour(DP)
- Just Sum It [UvaLive 5063] DP+组合数
- UVALive 4625 Garlands(二分答案 + DP)
- UVALive 3305Tour(双调DP)
- LeetCode——105. Construct Binary Tree from Preorder and Inorder Traversal
- 反转单链表
- 简单线程池实现原理
- Codeforces Round #432 (Div. 2) B. Arpa and an exam about geometry(数学水题)
- 几种常见加密算法解析及使用
- UVALive 4764 Bing it(dp)
- Linux的system()和popen()差异
- HTML表格颜色搭配+柱状图颜色搭配+HTML柱状图实现
- Windows Message Queue
- 引用参数传递
- NDK开发——FFmpeg在Linux下编译、测试编译结果
- hello!以后就在这里分享自己的学习进度和成果
- js:Jquery 异步提交表单(post)
- Oracle数据库体如何用才是最好用的呢?