社区讨论
求条
P4138[JOISC 2014] 挂饰 / Straps参与者 3已保存回复 3
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 3 条
- 当前快照
- 1 份
- 快照标识符
- @mkcg0btz
- 此快照首次捕获于
- 2026/01/13 18:22 上个月
- 此快照最后确认于
- 2026/01/17 11:00 上个月
至于为什么是 photo,是因为这个是校内的一场比赛,加强了这个题(能过原题)。
CPP#include<bits/stdc++.h>
using namespace std;
#define templete int T;cin>>T;while(T--)
#define _for(l,r) for(int i=l;i<=r;i++)
#define _rep(r,l) for(int i=r;i>=l;i--)
#define _rep2(r,l) for(int j=r;j>=l;j--)
#define int long long
const int N=4145141,inf=1e18;
struct photo{
int a,s;//钩子,好感
friend inline bool operator <(photo a,photo b){
return a.s<b.s;
}
}p1[N],p2[N];
int qzh[N],dp[N];
signed main(){
int n,ans=0,gou=1,tot1=0,tot2=0;
cin>>n;
_for(1,n){
int a,s;
cin>>a>>s;
if(a>0&&s>=0){//有钩用户,正
ans+=s,gou+=a-1;
}
else if(s>=0){//无钩用户,正
p1[++tot1]={a,s};
}
else if(a>1){//负
p2[++tot2]={a,s};
}
}
sort(p1+1,p1+tot1+1);
reverse(p1+1,p1+tot1+1);//排序使得最优
_for(1,tot1)qzh[i]=qzh[i-1]+p1[i].s;
_for(1,tot1)dp[i]=-inf;//统计选i个照片好感度最大值
//空间:.a-1(自己还要耗一个),价值:.s
dp[1]=0;
_for(1,tot2){
_rep2(n,p2[i].a-1){
dp[j]=max(dp[j],dp[j-p2[i].a+1]+p2[i].s);
}
}
int maxn=LLONG_MIN;
_for(1,n){
maxn=max(maxn,dp[i]+qzh[i+gou-1]);
}
cout<<maxn+ans;
return 0;
}
回复
共 3 条回复,欢迎继续交流。
正在加载回复...