当前位置:网站首页>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日
边栏推荐
- How to do well in member marketing three steps to teach you to understand member management
- fastjson的JSONArray和JSONObject[通俗易懂]
- HUST network attack and defense practice | 6_ IOT device firmware security experiment | Experiment 2 MPU based IOT device attack mitigation technology
- How can we reach members more effectively?
- Analysis report on China's photovoltaic inverter market prospect forecast and investment strategy recommendations in 2022
- JMeter response time and TPS listener tutorial
- 2022 edition of Beijing 5g industry investment planning and development prospect forecast analysis report
- dried food! Yiwen will show you SD card, TF card and SIM card!
- Encapsulate request request of uni app
- PolarisMesh系列文章——概念系列(一)
猜你喜欢

PHP laravel+gatewayworker completes im instant messaging and file transfer (Chapter 1: basic configuration)

Mqtt disconnect and reconnect

11、 Box styles and user interface

MOS管基本原理,单片机重要知识点

Fengshentai old shooting range Kali series

HUST network attack and defense practice | 6_ IOT device firmware security experiment | Experiment 3 freertos-mpu protection bypass

Prospering customs through science and technology, Ronglian and Tianjin Customs jointly build a genomic database and analysis platform
![[solved] data duplication or data loss after laravel paginate() paging](/img/68/7bf51bbf893a91bee24f5f7d4a369f.jpg)
[solved] data duplication or data loss after laravel paginate() paging

This executeQuery (SQL) cannot compile classes for JSP. What is the reason?

Scala problem solving the problem of slow SBT Download
随机推荐
Notice on printing and Distributing Measures for supporting strategic emerging industries and future industrial cluster development in Futian District, Shenzhen
2022 edition of China's medical robot industry investment status investigation and prospect dynamic analysis report
菜鸟实战UML——活动图
Statistical genetics: Chapter 1, basic concepts of genome
[redis series] redis learning 16. Redis Dictionary (map) and its core coding structure
Several problems encountered in setting up the environment in the past two days
Investment forecast and development strategy analysis report of China's rural sewage treatment industry in 2022
The best CMDB system
1、 MySQL introduction
[solved] laravel completes the scheduled job task (delayed distribution task) [execute a user-defined task at a specified time]
Investment planning and forecast report on the future direction of China's smart agriculture during the 14th five year plan (2022)
[probability theory] conditional probability, Bayesian formula, correlation coefficient, central limit theorem, parameter estimation, hypothesis test
Analysis report on China's photovoltaic inverter market prospect forecast and investment strategy recommendations in 2022
PHP laravel+gatewayworker completes im instant messaging and file transfer functions (Chapter 2: explanation of business logic)
Refined operation, extending the full life cycle value LTV
我想知道同花顺是炒股的么?在线开户安全么?
Build document editor based on slate
Assembly language (7) operation instruction
Random numbers in leetcode 710 blacklist [random numbers] the leetcode path of heroding
Loggie encoding and newline character test