Bing it
来源:互联网 发布:怎么在淘宝上传图片 编辑:程序博客网 时间:2024/05/16 11:46
对于每一个点可以有两种状态转移到它:1.由前面和它相同的数字转移到它 2.由它左侧的数字转移给它
Description
I guess most of you played cards on the trip to Harbin, but I‘m sure you have never played the following card game. This card game has N rounds and 100000 types of cards numbered from 1 to 100000. A new card will be opened when each round begins. You can ``bing" this new card. And if the card 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 first round and change it into 3 in the second round. You get no point in the third round, but get 1 point in the last round. Additionally, there is a special card 999. If you ``bing" it and it is opened again, you will get 3 point.
Given the order of N cards, tell me the maximum points you can get.
Input
The input file will contain multiple test cases. Each test case will consist of two lines. The first line of each test case contains one integer N(2N100000). The second line of each test case contains a sequence of n integers, indicating the order of cards. A single line with the number ``0" marks the end of input; do not process this case.
Output
For each input test case, print the maximum points you can get.
Sample Input
2 1 1 5 1 999 3 3 999 0
Sample Output
1 3
#include<stdio.h>#include<string.h>#include<algorithm>#define maxn 100005using namespace std;int main(){int n;while(scanf("%d",&n),n){int dp[maxn]={0},pre[maxn]={0},an[maxn]={0};for(int i=1;i<=n;i++){scanf("%d",&an[i]);}for(int i=1;i<=n;i++){if(pre[an[i]]!=0){if(an[i]==999){dp[i]=max(dp[i-1],dp[pre[an[i]]]+3);}else{dp[i]=max(dp[i-1],dp[pre[an[i]]]+1);}pre[an[i]]=i;}else{dp[i]=dp[i-1];pre[an[i]]=i;}}printf("%d\n",dp[n]);}return 0;}
- Bing it
- Bing it UVALive
- Bing It On Kattis
- Bing It On (Kattis
- UVALive 4764 Bing it
- Bing it UVALive
- uvalive 4764 Bing it 基础dp
- Bing it(动态规划)dp
- UVALive 4764 Bing it(dp)
- BING
- BING
- Bing = But It's Not Google,必应的深层含义
- bing统计
- bing-img
- bing搜索
- Bing获取-获取Bing每日图片
- 我看Bing行
- bing之初体验
- Python ConfigParser使用
- Java常用日志框架基础介绍
- Idea设置提示syso、syse等等
- Flume日志采集框架
- 二叉树的层次,中序非递归遍历,以递归前序的方式构造二叉树,将二叉树中的e更新为d,输出从根结点出发 到指定结点,依次经过的祖先(即路径),由前序和中序还原二叉树
- Bing it
- hdu 6134
- Zookeeper应用场景
- Java中throws和throw的区别
- hdu 6069 Counting Divisors(2017多校第四场)
- composer 安装 Laravel 出现的问题
- java中 IndexOf()、lastIndexOf()、substring()的用法
- Centos7安装Mysql5.7
- 丑数