当前位置:网站首页>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日
边栏推荐
- Ctfshow web getting started command execution web75-77
- [redis series] redis learning 16. Redis Dictionary (map) and its core coding structure
- Mqtt disconnect and reconnect
- Common problems and Thoughts on member operation management
- Scala-day01- companion objects and HelloWorld
- Investment planning and forecast report on the future direction of China's smart agriculture during the 14th five year plan (2022)
- VMware虚拟机 桥接模式 无法上网 校园网「建议收藏」
- AD - 将修改后的 PCB 封装更新到当前 PCB 中
- Analysis report on the "fourteenth five year plan" and investment prospect of China's pharmaceutical equipment industry 2022-2028
- ctfshow web入门 命令执行web75-77
猜你喜欢

Realize microservice load balancing (ribbon)
![[solved] data duplication or data loss after laravel paginate() paging](/img/68/7bf51bbf893a91bee24f5f7d4a369f.jpg)
[solved] data duplication or data loss after laravel paginate() paging
女性科学家的流失
![[graduation season · advanced technology Er] I remember the year after graduation](/img/e7/8e1dafa561217b77a3e3992977a8ec.png)
[graduation season · advanced technology Er] I remember the year after graduation

Black squares in word
![[solved] laravel completes the scheduled job task (delayed distribution task) [execute a user-defined task at a specified time]](/img/13/c2c63333a9e5ac08b339449ea17654.jpg)
[solved] laravel completes the scheduled job task (delayed distribution task) [execute a user-defined task at a specified time]

Ctrip ticket app KMM cross end kV repository mmkv kotlin | open source

HUST网络攻防实践|6_物联网设备固件安全实验|实验三 FreeRTOS-MPU 保护绕过

Deep thinking from senior member managers

JMeter response time and TPS listener tutorial
随机推荐
Leetcode 78. Subset and 90 Subset II
请指教同花顺是什么软件?在线开户安全么?
Leetcode 78. 子集 and 90. 子集 II
How to do well in member marketing three steps to teach you to understand member management
2022 edition of China's medical robot industry investment status investigation and prospect dynamic analysis report
Realize microservice load balancing (ribbon)
2022 edition of China's cotton chemical fiber printing and dyeing Market Status Investigation and Prospect Forecast Analysis Report
Which is safer and better for great wisdom to open an account
Microservice governance (nocas)
leetcode 715. Range module (hard)
Statistical genetics: Chapter 1, basic concepts of genome
Redis cannot connect to the server through port 6379
Random numbers in leetcode 710 blacklist [random numbers] the leetcode path of heroding
2022 edition of investment analysis and "fourteenth five year plan" development prospect forecast report of China's switchgear industry
I want to know how the top ten securities firms open accounts? Is online account opening safe?
2、 MySQL Foundation
PHP uses laravel pay component to quickly access wechat jsapi payment (wechat official account payment)
Encapsulate request request of uni app
Research on the current situation of China's modified engineering plastics market and demand forecast analysis report 2022-2028
One click deployment CEPH script