UVALive 4764 简单dp水题(也可以暴力求解)
Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu
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(2N
100000). 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<iostream>
#include<algorithm>
using namespace std; int dp[];
bool vis[];
int a[]; int main(){
int n; while(scanf("%d",&n)!=EOF){
if(n==)
break; memset(dp,,sizeof(dp));
memset(a,,sizeof(a));
memset(vis,false,sizeof(vis)); for(int i=;i<n;i++){
scanf("%d",&a[i]);
} int sum=-; int point=a[];
vis[point]=true; for(int i=;i<n;i++){
int next=a[i];
if(!vis[next]){ dp[next]=dp[point];
vis[next]=true;
}
else{
if(next==){
dp[next]=max(dp[point],dp[next]+);
}
else{
dp[next]=max(dp[point],dp[next]+);
}
} point=next; if(dp[next]>sum)
sum=dp[next]; }
printf("%d\n",sum);
}
return ;
}
UVALive 4764 简单dp水题(也可以暴力求解)的更多相关文章
- 简单dp水题
#include <bits/stdc++.h> using namespace std; #define limit (100 + 5)//防止溢出 #define INF 0x3f3f ...
- ACM :漫漫上学路 -DP -水题
CSU 1772 漫漫上学路 Time Limit: 1000MS Memory Limit: 131072KB 64bit IO Format: %lld & %llu Submit ...
- [poj2247] Humble Numbers (DP水题)
DP 水题 Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The se ...
- Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题
除非特别忙,我接下来会尽可能翻译我做的每道CF题的题面! Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题 题面 胡小兔和司公子都认为对方是垃圾. 为了决出谁才是垃 ...
- 13年山东省赛 The number of steps(概率dp水题)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud The number of steps Time Limit: 1 Sec Me ...
- 2019年华南理工校赛(春季赛)--I--炒股(简单思维水题)
水题,想想就过了 题目如下: 链接:https://ac.nowcoder.com/acm/contest/625/I来源:牛客网 攒机一时爽,一直攒机一直爽. 沉迷攒机的胡老师很快就发现,他每天只能 ...
- dp水题 序列问题 (9道)
9道题.A了8道,A题看题解也没弄懂怎么维护m段子序列的,过一段时间再回来看看 dp试水 47:56:23 125:00:00 Overview Problem Status Rank ( ...
- 【BZOJ】1270: [BeijingWc2008]雷涛的小猫(DP+水题)
http://www.lydsy.com/JudgeOnline/problem.php?id=1270 这完全是一眼题啊,但是n^2的时间挺感人.(n^2一下的级别请大神们赐教,我还没学多少dp优化 ...
- 学校作业-Usaco DP水题
好吧,因为USACO挂掉了,所以我写的所有代码都不保证正确性[好的,这么简单的题,再不写对,你就可以滚粗了! 第一题是USACO 2.2.2 ★Subset Sums 集合 对于从 1 到 N 的连 ...
随机推荐
- war和war exploded的区别
是选择war还是war exploded 这里首先看一下他们两个的区别: (1)war模式这种可以称之为是发布模式,看名字也知道,这是先打成war包,再发布: (2)war exploded模式是直接 ...
- Logback初始化失败问题排查(Web.xml中context-param配置详解)
监控部分反馈异常,生产系统日志文件竟然木有了(最后一次版本发布后,再也无日志文件生成). 问题排查步骤: 1. 检查logback配置文件 日志生成目录一切正常 应该服务器上磁盘空间未满.操作权限没有 ...
- Spring 学习之bean的理解
前言:对于使用Spring框架的开发人员来说,我们主要做的主要有两件事情:①开发Bean;②配置Bean;而Spring帮我们做的就是根据配置文件来创建Bean实例,并调用Bean实例的方法来完成“依 ...
- lintcode_69_二叉树的层次遍历
二叉树的层次遍历 描述 笔记 数据 评测 给出一棵二叉树,返回其节点值的层次遍历(逐层从左往右访问) 您在真实的面试中是否遇到过这个题? Yes 哪家公司问你的这个题? LinkedIn Airb ...
- 关于Ubuntu 16.04 pip安装Docker-Compose
$ sudo apt-get update 安装pip: $ sudo apt-get install python-pip 卸载旧版本docker-compose: $ sudo pip unins ...
- Python生成器、装饰器
## 生成器 - 生成器是用来创建Python序列的一个对象 - 通常生成器是为迭代器产生数据的 - 例如range()函数就是一个生成器 - 每次迭代生成器时,它都会记录上一次调用的位置,并返回下一 ...
- 详解JavaScript中的arc的方法
今天说说JavaScript在网页中画圆的函数arc! 一.arc所需要的参数设置 1 arc(x, y, radius, startAngle, endAngle, counterclockwise ...
- php解决sql_server连接问题
1.首先根据phpinfo()查看当前php版本以及线程安全情况(ts或者nts):2.下载sqlsrv扩展(适用32位php) 下载链接为https://www.microsoft.com/en-u ...
- [Bzoj3894]文理分科(最小割)
Description 文理分科是一件很纠结的事情!(虽然看到这个题目的人肯定都没有纠结过) 小P所在的班级要进行文理分科.他的班级可以用一个n*m的矩阵进行描述,每个格子代表一个同学的座位.每位 ...
- 財務会計管理(FI&CO)
FI(財務会計)系のSAP DBテーブル.随時更新していきます. [勘定コードマスタ]SKA1: 勘定コードマスタ(勘定コード表データ)SKB1: 勘定コードマスタ(会社コードデータ)SKAT: テキ ...