Light oj 1217 - Neighbor House (II)(dp)
来源:互联网 发布:linux运维的基础知识 编辑:程序博客网 时间:2024/05/03 11:33
A soap company wants to advertise their product in a local area. In this area, there are n houses and the houses are placed in circular fashion, such that house 1 has two neighbors: house 2 and n. House 5has two neighbors: house 4 and 6. House n has two neighbors, house n-1 and 1.
Now the soap company has an estimation of the number of soaps they can sell on each house. But for their advertising policy, if they sell soaps to a house, they can't sell soaps to its two neighboring houses. No your task is to find the maximum number of estimated soaps they can sell in that area.
Input
Input starts with an integer T (≤ 100), denoting the number of test cases.
Each case starts with a line containing an integer n (2 ≤ n ≤ 1000). The next line contains n space separated integers, where the ith integer denotes the estimated number of soaps that can be sold to the ithhouse. Each of these integers will lie in the range [1, 1000].
Output
For each case, print the case number and the maximum number of estimated soaps that can be sold in that area.
Sample Input
Output for Sample Input
3
2
10 100
3
10 2 11
4
8 9 2 8
Case 1: 100
Case 2: 11
Case 3: 17
#pragma comment(linker, "/STACK:1024000000,1024000000")#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<queue>#include<stack>#include<vector>#include<map>#define L(x) (x<<1)#define R(x) (x<<1|1)#define MID(x,y) ((x+y)>>1)#define bug printf("hihi\n")#define eps 1e-12typedef long long ll;using namespace std;#define N 1005int a[N];int n;int dp[2][N][2];int main(){ int i,j,t,ca=0; scanf("%d",&t); while(t--) { scanf("%d",&n); for(i=1;i<=n;i++) scanf("%d",&a[i]); memset(dp,0,sizeof(dp)); dp[0][1][0]=0; dp[1][1][1]=a[1]; for(int i=2;i<=n;i++) { dp[0][i][1]=a[i]+dp[0][i-1][0]; dp[0][i][0]=max(dp[0][i-1][1],dp[0][i-1][0]); dp[1][i][1]=a[i]+dp[1][i-1][0]; dp[1][i][0]=max(dp[1][i-1][1],dp[1][i-1][0]); } dp[1][n][1]-=a[n]; int ans=0; ans=max(dp[0][n][0],dp[0][n][1]); ans=max(ans,dp[1][n][0]); ans=max(ans,dp[1][n][1]); printf("Case %d: %d\n",++ca,ans); } return 0;}
- Light oj 1217 - Neighbor House (II)(dp)
- Light OJ 1217 Neighbor House (II) (环形DP)
- 【light-oj】-1047 - Neighbor House(dp)
- Light oj 1047 - Neighbor House (简单dp)
- Light OJ 1047 Neighbor House(简单DP)
- LightOJ - 1217 Neighbor House (II)(dp)
- Light OJ 1047 Neighbor House
- Light OJ 1047 Neighbor House
- LIGHT OJ 1047 - Neighbor House 【DP数塔】
- lightoj 1217 - Neighbor House (II) DP
- light oj 1047 - Neighbor House 动态规划
- Neighbor House (II) LightOJ
- lightOJ 1047 Neighbor House (DP)
- LightOJ 1047 - Neighbor House(dp)
- LightOJ 1047 - Neighbor House (dp)
- LightOj 1047 Neighbor House(基础dp)
- 【LightOJ】1047 - Neighbor House(dp)
- Lightoj1047——Neighbor House(dp)
- 2015-09-28
- 【0】结对编程与驾驶
- gem5运行Multiprogrammed workloads的方法
- ubuntu VirtualBox中实现与主机文件的共享
- 马踏飞燕(续)
- Light oj 1217 - Neighbor House (II)(dp)
- android6.0新建项目中appcompat_v7导入问题以及导入的项目xml问题
- NYOJ139 我排第几个
- jsoup
- 05_树
- ocp-v13-049
- 第二节 HTML基本架构学习
- OCP-V13-050
- 选择排序法