T1
水题 100
T2优化三:当输入所有点的工作限度加起来都小于n-1时,我们cout<<-1;
考场上脑子一抽暴力挂了 0
T3的时候,能不能形成最优解
考场上
1.好像n^4可以哎
2.第一维可以单调队列哎~n^3了
3.第二维可以主席树哎~n^2log了
4.第三位好像可以莫队搞一搞,要不线段树套平衡树~哎呀n sqrt(n) log(n)了哎
5.优化优化常数,应该有暴力分吧
等等,我写了半天只有暴力分!?
然后就爆蛋了
附上代码
//Copyright(c)2015 liuchenrui #include<cstdio> #include<ctime> #include<iostream> #include<algorithm> #include<cstring> using namespace std; inline void R(int &v) { v=0;char c=0;int p=1; while(c<'0' || c>'9'){if(c=='-')p=-1;c=getchar();} while(c>='0' && c<='9'){v=(v<<3)+(v<<1)+c-'0';c=getchar();} v*=p; } int s[1000000]; int main() { freopen("compress.in","r",stdin); freopen("compress.out","w",stdout); int n;R(n);n>>=3; for(int i=1;i<=n;i++) { int x;R(x); for(int t=i<<3;t>(i<<3)-8;t--) { s[t]=(x&1); x>>=1; } } for(int i=1;i<=(n<<3);i++) { int j; for(j=i;j<=i+127 && j<=(n<<3);j++) { if(s[j]!=s[i])break; } if(s[i]==1)printf("%d ",j-i+128); else printf("%d ",j-i); i=j-1; } }
//Copyright(c)2015 liuchenrui #include<cstdio> #include<ctime> #include<iostream> #include<algorithm> #include<cstring> #define inf 1000000000 using namespace std; inline void R(int &v) { v=0;char c=0;int p=1; while(c<'0' || c>'9'){if(c=='-')p=-1;c=getchar();} while(c>='0' && c<='9'){v=(v<<3)+(v<<1)+c-'0';c=getchar();} v*=p; } int T=0; int zy[20]; int a[20]; int map[22][22],tot=0; int t[22]; int n,d; int ans; int father[22]; int deep[22]; inline void dfs(int now,int tmpans) { //if(clock()>2950)return; if(tmpans>=ans)return; if(now==n+1) { int ret=0; for(int i=1;i<=n;i++)ret=max(ret,t[i]); ans=min(ans,ret); return; } if(now+1<=tot) dfs(now+1,tmpans); for(int i=2;i<n;i++) { if(!exist[i]&&deep[now]+1<=d&&a[now]>=1) { exist[i]=true; t[i]=t[now]+map[now][i]; t[now]+=map[now][i]; deep[i]=deep[now]+1; a[now]--; dfs(now,max(tmpans,t[i])); exist[i]=false; t[now]-=map[now][i]; a[now]++; } } /* for(int i=1;i<=n;i++) { //if(clock()>2950)return; //if(i!=now)continue; // if(father[i]!=i)continue; for(int j=1;j<=n;j++) { //if(!a[j])continue; //if(father[j]==j)continue; //if(deep[j]==d)continue; a[j]--; t[i]=t[j]=t[j]+map[j][i]; deep[i]=deep[j]+1;father[i]=j; dfs(now+1,max(tmpans,t[i])); a[j]++; deep[i]=0;father[i]=i; t[i]=0;t[j]-=map[j][i]; } }*/ } int main() { freopen("qin.in","r",stdin); //freopen("qin.out","w",stdout); while(cin>>n) { //T++; int T=0; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) R(map[i][j]); for(int i=1;i<=n;i++)R(a[i]),father[i]=i,T+=a[i]; father[1]=0;R(d);ans=inf; if(a[1]==0 && n==1)printf("0\n"),exit(0); if(a[1]==0){printf("-1\n");continue;} if(T<n-1){printf("-1\n");continue;} dfs(1,0); if(ans==inf)printf("-1\n"); else printf("%d\n",ans); } }
//Copyright(c)2015 liuchenrui #include<cstdio> #include<ctime> #include<iostream> #include<algorithm> #include<cstring> #define ll long long using namespace std; inline void R(ll &v) { v=0;char c=0;ll p=1; while(c<'0' || c>'9'){if(c=='-')p=-1;c=getchar();} while(c>='0' && c<='9'){v=(v<<3)+(v<<1)+c-'0';c=getchar();} v*=p; } ll dp[500005][3]; ll a[500010]; ll b[500010]; ll n; int main() { freopen("base.in","r",stdin); freopen("base.out","w",stdout); R(n); for(int i=1;i<=n;i++)R(a[i]); for(int i=1;i<=n;i++)R(b[i]); ll ans=0; for(int i=1;i<=n;i++) { dp[i][0]=max(dp[i-1][0]+a[i]+b[i],a[i]+b[i]); if(i>=2)dp[i][1]=max(dp[i-1][0]+b[i],dp[i-1][1]+b[i]); if(i>=3)dp[i][2]=max(dp[i-1][1]+a[i]+b[i],dp[i-1][2]+a[i]+b[i]); } for(int i=3;i<=n;i++) ans=max(ans,dp[i][2]); cout<<ans<<endl; }