当前位置:网站首页>7-2 a Fu the thief
7-2 a Fu the thief
2022-06-26 13:21:00 【White -】
7-2 Ah Fu, the thief
Ah Fu is an experienced thief . Take advantage of the dark moon and the high wind , Ah Fu is going to rob a shop on the street tonight .
There are a total of N Shops , There's some cash in every store .
Ah Fu investigated in advance and learned that , Only when he looted two adjacent shops at the same time , The alarm system on the street will start , Then the police will flock .
As a thief who has always committed crimes carefully , Ah Fu doesn't want to steal at the risk of being chased by the police .
He wants to know , Without alerting the police , The maximum amount of cash he can get tonight ?
Input format
The first line of input is an integer T, Means that there are T Group data .
The next set of data , The first line is an integer N , Means that there are N Shops .
The second line is N A positive integer separated by spaces , Indicates the amount of cash in each store .
The amount of cash in each store does not exceed 1000.
Output format
For each set of data , Output one line .
This line contains an integer , It means the amount of cash a Fu can get without alerting the police .
Data range
1≤T≤50,
1≤N≤105
sample input :
2
3
1 8 2
4
10 7 6 14
sample output :
8
24
Code :
#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 Japan
边栏推荐
- tauri vs electron
- [how to connect the network] Chapter 2 (Part 1): establish a connection, transmit data, and disconnect
- C - Common Subsequence
- Solutions to insufficient display permissions of find and Du -sh
- 利用scrapy爬取句子迷网站优美句子存储到本地(喜欢摘抄的人有福了!)
- Use the script to crawl the beautiful sentences of the sentence fan website and store them locally (blessed are those who like to excerpt!)
- E - Apple Catching
- Processing polyhedron change
- LeetCode_ Stack_ Medium_ 150. evaluation of inverse Polish expression
- MediaPipe手势(Hands)
猜你喜欢
Summary of wechat applet test points

What are the common categories of software testing?

Prototype

2、并行接口、协议和相关芯片介绍(8080、8060)

Fire warning is completed within 10 seconds, and Baidu AI Cloud helps Kunming Guandu build a new benchmark of smart city

Arcpy——InsertLayer()函數的使用:摻入圖層到地圖文檔裏

MySQL数据库讲解(三)

Design of simple digital circuit traffic light
![[how to connect the network] Chapter 1: the browser generates messages](/img/6b/e85f29ba97c261e01e177b5e77c423.png)
[how to connect the network] Chapter 1: the browser generates messages

Mysql database explanation (III)
随机推荐
橋接模式(Bridge)
E - Apple Catching
Common faults of MySQL database - forgetting database password
HDU 5860
POJ 3070 Fibonacci
Script - crawl the customized storage path of the cartoon and download it to the local
MySQL explanation (II)
Composite mode
Electron official docs series: Development
Arcpy——InsertLayer()函数的使用:掺入图层到地图文档里
Beifu realizes the control of time slice size and quantity through CTU and ton
Decorator
Use the script to crawl the beautiful sentences of the sentence fan website and store them locally (blessed are those who like to excerpt!)
sed编辑器
组合模式(Composite )
J - Wooden Sticks poj 1065
[shell] generate strings between specified dates
Uva5009 error curves three points
适配器模式(Adapter)
A few lines of code can realize complex excel import and export. This tool class is really powerful!