# yzoj P2344 斯卡布罗集市 题解

3 8 20 8 15 12 12 25


o x o x o x x

#include<bits/stdc++.h>
using namespace std;
int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')
f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9'){
x=(x<<1)+(x<<3)+(ch^48);
ch=getchar();
}
return x*f;
}
int t,n;
long long f[310][1510],ans,tmp1,tmp2;
int main(){
for(int i=1;i<=t;++i){
for(int j=1;j<=n;++j){
}
if(n&1){
for(int j=1;j<=n;++j){
if(j&1) ans+=f[i][j];
}
}
else{
tmp2=0;
for(int j=0;j<=n;++j){
tmp1=0;
for(int k=1;k<j;k+=2){
tmp1+=f[i][k];
}
for(int k=j+2;k<=n;k+=2){
tmp1+=f[i][k];
}
tmp2=max(tmp1,tmp2);
}
ans+=tmp2;
}
}
printf("%lld",ans);
return 0;
}


#include<algorithm>
#include<cstdio>
#define ll long long
#define MX 10001
using namespace std;
int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')
f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9'){
x=(x<<1)+(x<<3)+(ch^48);
ch=getchar();
}
return x*f;
}
int T,n;
ll ans=0;
int a[MX];
ll suml[MX],sumr[MX];
int main(){
while(T--){
sumr[n+1]=0;
for(int i=1;i<=n;++i){
if(i&1){
suml[i]=suml[i-1]+a[i];
}else{
suml[i]=suml[i-1];
}
}
if(n&1){
ans+=suml[n];
}else{
for(int i=n;i>=1;--i){
if(i&1){
sumr[i]=sumr[i+1];
}else{
sumr[i]=sumr[i+1]+a[i];
}
}
ll sum=0;
for(int i=1;i<=n;++i){
sum=max(sum,suml[i-1]+sumr[i+1]);
}
ans+=sum;
}
}
printf("%lld",ans);
return 0;
}


posted @ 2019-08-27 09:52  End_donkey  阅读(186)  评论(0编辑  收藏  举报