标签:cout mat ons ace class log turn lin for
题面:https://www.cnblogs.com/Juve/articles/11487699.html
队长快跑:
权值线段树与dp
yy的不错
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std; const int MAXN=1e5+5; int n,a[MAXN],b[MAXN],ans=0,lsh[MAXN<<1],cnt,tot=0; struct node{ int l,r,laz,mx; }tr[MAXN<<4]; void build(int k,int l,int r){ tr[k].l=l,tr[k].r=r; if(l==r){ tr[k].mx=0; return ; } int mid=(l+r)>>1; build(k<<1,l,mid); build(k<<1|1,mid+1,r); } void down(int k){ tr[k<<1].laz+=tr[k].laz; tr[k<<1|1].laz+=tr[k].laz; tr[k<<1].mx+=tr[k].laz; tr[k<<1|1].mx+=tr[k].laz; tr[k].laz=0; } void pushup(int k){ tr[k].mx=max(tr[k<<1].mx,tr[k<<1|1].mx); } int query_max(int k,int opl,int opr){ int l=tr[k].l,r=tr[k].r; if(opl<=l&&r<=opr) return tr[k].mx; if(tr[k].laz) down(k); int mid=(l+r)>>1,res=0; if(opl<=mid) res=max(res,query_max(k<<1,opl,opr)); if(opr>mid) res=max(res,query_max(k<<1|1,opl,opr)); return res; } void update(int k,int opt,int val){ int l=tr[k].l,r=tr[k].r; if(l==r){ tr[k].mx=max(tr[k].mx,val); return ; } if(tr[k].laz) down(k); int mid=(l+r)>>1; if(opt<=mid) update(k<<1,opt,val); else update(k<<1|1,opt,val); pushup(k); } void change(int k,int opl,int opr){ int l=tr[k].l,r=tr[k].r; if(opl<=l&&r<=opr){ ++tr[k].mx; ++tr[k].laz; return ; } if(tr[k].laz) down(k); int mid=(l+r)>>1; if(opl<=mid) change(k<<1,opl,opr); if(opr>mid) change(k<<1|1,opl,opr); pushup(k); } signed main(){ scanf("%d",&n); for(int i=1;i<=n;++i){ scanf("%d%d",&a[i],&b[i]); lsh[++tot]=a[i],lsh[++tot]=b[i]; } sort(lsh+1,lsh+tot+1); cnt=unique(lsh+1,lsh+tot+1)-lsh; for(int i=1;i<=n;++i){ a[i]=lower_bound(lsh+1,lsh+cnt+1,a[i])-lsh; b[i]=lower_bound(lsh+1,lsh+cnt+1,b[i])-lsh; } build(1,1,cnt); for(int i=n;i>=1;--i){ if(a[i]>b[i]){ int p=query_max(1,1,b[i]-1)+1; update(1,b[i],p); change(1,b[i]+1,a[i]); }else{ int p=query_max(1,1,a[i]-1)+1; update(1,b[i]+1,p); } } printf("%d\n",tr[1].mx); return 0; }
抛硬币:
乱搞dp
#include<iostream> #include<cstdio> #include<cstring> #include<queue> using namespace std; const int MAXN=3005; const int mod=998244353; int l,len,f[MAXN][MAXN],s[MAXN]; char ch[MAXN]; signed main(){ scanf("%s",ch+1); scanf("%d",&l); len=strlen(ch+1); //cout<<len<<endl; for(int i=1;i<=len;++i){ f[i][0]=1; for(int j=i-1;j>=1;--j){ if(ch[j]==ch[i]){ s[i]=j; break; } } } //for(int i=1;i<=len;++i) cout<<s[i]<<endl; f[0][0]=1; for(int i=1;i<=len;++i){ for(int j=1;j<=l;++j){ if(s[i]!=0) f[i][j]=((f[i-1][j]+f[i-1][j-1]-f[s[i]-1][j-1])%mod+mod)%mod; else f[i][j]=(f[i-1][j]+f[i-1][j-1])%mod; } } printf("%d\n",f[len][l]); return 0; }
HZOI20190908模拟40 队长快跑,影魔,抛硬币 题解
标签:cout mat ons ace class log turn lin for
原文地址:https://www.cnblogs.com/Juve/p/11487702.html