当前位置:网站首页>7-2 大盗阿福
7-2 大盗阿福
2022-06-26 12:32:00 【白—】
7-2 大盗阿福
阿福是一名经验丰富的大盗。趁着月黑风高,阿福打算今晚洗劫一条街上的店铺。
这条街上一共有 N 家店铺,每家店中都有一些现金。
阿福事先调查得知,只有当他同时洗劫了两家相邻的店铺时,街上的报警系统才会启动,然后警察就会蜂拥而至。
作为一向谨慎作案的大盗,阿福不愿意冒着被警察追捕的风险行窃。
他想知道,在不惊动警察的情况下,他今晚最多可以得到多少现金?
输入格式
输入的第一行是一个整数 T,表示一共有 T 组数据。
接下来的每组数据,第一行是一个整数 N ,表示一共有 N 家店铺。
第二行是 N 个被空格分开的正整数,表示每一家店铺中的现金数量。
每家店铺中的现金数量均不超过1000。
输出格式
对于每组数据,输出一行。
该行包含一个整数,表示阿福在不惊动警察的情况下可以得到的现金数量。
数据范围
1≤T≤50,
1≤N≤105
输入样例:
2
3
1 8 2
4
10 7 6 14
输出样例:
8
24
代码:
#include <iostream>
#include<string.h>
#include<math.h>
using namespace std;
int t,n,maxx;
int a[200];
int f[200][2];
int main()
{
cin>>t;
while(t--)
{
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i];
for(int i=1;i<=n;i++)
{
f[i][0]=max(f[i-1][0],f[i-1][1]);
f[i][1]=f[i-1][0]+a[i];
}
cout<<max(f[n][0],f[n][1])<<endl;
}
return 0;
}
202206260900日
边栏推荐
- PHP laravel+gatewayworker completes im instant messaging and file transfer (Chapter 1: basic configuration)
- 11、 Box styles and user interface
- Precautions for opening a securities account is it safe to open an account
- [redis series] redis learning 16. Redis Dictionary (map) and its core coding structure
- Hello! Forward proxy!
- 2022 edition of Beijing 5g industry investment planning and development prospect forecast analysis report
- Introduction to Dolby panoramic sound
- Oracle锁表查询和解锁方法
- PHP uses laravel pay component to quickly access wechat jsapi payment (wechat official account payment)
- Investment planning and forecast report on the future direction of China's smart agriculture during the 14th five year plan (2022)
猜你喜欢
How to calculate flops and params in deep learning
1、 MySQL introduction
【概率论】条件概率、贝叶斯公式、相关系数、中心极限定理、参数估计、假设检验
Comparison of latest mobile phone processors in 2020 (with mobile phone CPU ladder diagram)
Loggie encoding and newline character test
Laravel+gatewayworker completes the im instant messaging and file transfer functions (Chapter 4: server debugging errors)
4. N queen problem
Ctfshow web getting started command execution web75-77
Matlab programming example: how to count the number of elements in a cell array
Spark-day01- get started quickly
随机推荐
Scala-day02- variables and data types
我想知道同花顺是炒股的么?在线开户安全么?
Research on the current situation of China's modified engineering plastics market and demand forecast analysis report 2022-2028
How to do well in member marketing three steps to teach you to understand member management
Ad - update the modified PCB package to the current PCB
Analysis report on the "fourteenth five year plan" and investment prospect of China's pharmaceutical equipment industry 2022-2028
Is it safe to open a securities account
女性科学家的流失
房租是由什么决定的
UDP协议详解[通俗易懂]
New routing file in laravel framework
Cross platform members get through the two channels of brand Ren Du
dried food! Yiwen will show you SD card, TF card and SIM card!
PHP laravel+gatewayworker completes im instant messaging and file transfer (Chapter 1: basic configuration)
Basic principle of MOS tube and important knowledge points of single chip microcomputer
MySQL optimization - index (what is an index?)
HUST網絡攻防實踐|6_物聯網設備固件安全實驗|實驗二 基於 MPU 的物聯網設備攻擊緩解技術
11、 Box styles and user interface
Using the methods in the repository to solve practical problems
Five problems and solutions of member operation