今天早上起来状态不如昨天,上来就做软件安装:
I. 软件安装
题目类型:传统 评测方式:文本比较
题目描述
输入格式
输出格式
样例
这题上来就知道是反向建边,然后跑树批(树上dp)然后就开始码,并没有看标签,以为这就是上天赐予的水题,满怀信心要AC他,dp式子也写对了,也建虚根节点了,然而
惊喜爆10,一看标签,省选,靠,不是水题(宝宝不开心!)然后就想了一想,自己又手膜了一个样例然后就发现会出现环,例如1 3 2 1时就会出现环,所以需要什么?
tarjin(orz)缩点啊,然后,然后就A了;
码:
1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 #include<cstring> 5 #include<stack> 6 using namespace std; 7 #define LL long long 8 //powered by lsc; 9 const LL maxn=8000; 10 LL head[maxn],ver[maxn],nxt[maxn],tot,d[maxn],cntt; 11 struct chu{ 12 LL x,y,head,nxt; 13 }s[maxn]; //edge; 14 15 LL w[maxn],v[maxn],dp[3000][3000]; 16 LL n,m,ans; //problom; 17 18 LL dfn[maxn],low[maxn],belong[maxn],cp[maxn],cnt,vis[maxn],cw[maxn];//cp is the v value,cw is the w value; 19 stack<LL>ss; 20 inline void add(LL x,LL y){ver[++tot]=y;nxt[tot]=head[x];head[x]=tot;} 21 inline void ADD(LL x,LL y){s[++cntt].y=y;s[cntt].x=x;s[cntt].nxt=s[x].head;s[x].head=cntt;} 22 void dfs(LL x) 23 { 24 dfn[x]=low[x]=++cnt; 25 ss.push(x); 26 vis[x]=1; 27 for (LL i=s[x].head;i;i=s[i].nxt) 28 if (!dfn[s[i].y]) 29 dfs(s[i].y), 30 low[x]=min(low[x],low[s[i].y]); 31 else if (vis[s[i].y]) 32 low[x]=min(low[x],dfn[s[i].y]); 33 if (dfn[x]==low[x]) 34 { 35 cp[x]=0;LL ress=0; 36 for (LL y=-1;y!=x;y=ss.top(),ss.pop()) 37 { 38 belong[ss.top()]=x, 39 cp[x]+=v[ss.top()], 40 cw[x]+=w[ss.top()], 41 vis[ss.top()]=0; 42 } 43 } 44 } 45 void solve(LL x,LL fa) 46 { 47 for(LL i=cw[x];i<=m;i++) 48 dp[x][i]=cp[x]; 49 for(LL i=head[x];i;i=nxt[i]) 50 { 51 LL y=ver[i]; 52 if(y==fa)continue;solve(y,x); 53 for(LL o=m-cw[x];o>=0;o--) 54 for(LL u=0;u<=o;u++) 55 dp[x][o+cw[x]]=max(dp[x][o+cw[x]],dp[y][u]+dp[x][o+cw[x]-u]); 56 } 57 } 58 int main() 59 { 60 //freopen("cnm.txt","r",stdin); 61 scanf("%lld%lld",&n,&m); 62 for(LL i=1;i<=n;i++) 63 scanf("%lld",&w[i]); 64 for(LL i=1;i<=n;i++) 65 scanf("%lld",&v[i]); 66 for(LL i=1;i<=n;i++){LL vp=0;scanf("%lld",&vp);if(vp==0)continue;ADD(vp,i);} 67 //for(LL i=1;i<=n;i++)if(d[i]==0)ADD(0,i); //xu root; 68 for(LL i=1;i<=n;i++)if(!dfn[i])dfs(i); 69 for(LL j=1;j<=cnt;j++) 70 { 71 if(belong[s[j].x]!=belong[s[j].y]) 72 //printf("%d %d start point value:%d end point value:%d ",belong[i],belong[s[j].y],cw[belong[i]],cw[belong[s[j].y]]), 73 add(belong[s[j].x],belong[s[j].y]), 74 d[belong[s[j].y]]++; 75 } 76 for(int i=1;i<=n;i++)if(d[i]==0)add(0,i); 77 solve(0,0); 78 printf("%lld ",dp[0][m]); 79 return 0; 80 }
E. 太鼓达人
内存限制:128 MiB 时间限制:1000 ms 标准输入输出
题目类型:传统 评测方式:文本比较
题目描述
输入格式
输出格式
样例
这题水题,爆搜就能A,其实打表也可以A,不用考虑复杂度问题,直接干!
爆搜:
1 #include<iostream> 2 #include<cstdio> 3 using namespace std; 4 int k,b[2050],jud[2050][2050],mas,cnt; 5 bool v[2050],t[2050]; 6 void dfs(int x) 7 { 8 for(int i=0;i<=mas;i++) 9 if(jud[x][i]&&!v[i]) 10 jud[x][i]=0, 11 v[i]=1,dfs(i); 12 b[++cnt]=x; 13 } 14 int main() 15 { 16 scanf("%d",&k); 17 mas=(1<<k)-1; 18 //memset(jud,-1,sizeof(jud)); 19 for(int i=0;i<=mas;i++) 20 { 21 int nt=(i<<1)&mas; 22 //cout<<nt;===next permutation; 23 t[nt|1]=1;t[nt]=0; 24 if((nt|1)!=i) jud[i][nt|1]=1; 25 if(nt!=i) jud[i][nt]=1; 26 } 27 dfs(0); 28 printf("%d ",mas+1); 29 for(int i=1;i<=k;i++) printf("0"); 30 for(int i=cnt-1;i>k;i--) printf("%d",t[b[i]]); 31 }
这里附赠lnc打表代码(默默的谴责!)
1 #include<iostream> 2 #include<cstdio> 3 using namespace std; 4 int n; 5 int main() 6 { 7 scanf("%d",&n); 8 if(n==2) puts("4 0011"); 9 if(n==3) puts("8 00010111"); 10 if(n==4) puts("16 0000100110101111"); 11 if(n==5) puts("32 00000100011001010011101011011111"); 12 if(n==6) puts("64 0000001000011000101000111001001011001101001111010101110110111111"); 13 if(n==7) puts("128 00000001000001100001010000111000100100010110001101000111100100110010101001011100110110011101001111101010110101111011011101111111"); 14 if(n==8) puts("256 0000000010000001100000101000001110000100100001011000011010000111100010001001100010101000101110001100100011011000111010001111100100101001001110010101100101101001011110011001101010011011100111011001111010011111101010101110101101101011111011011110111011111111"); 15 if(n==9) puts("512 00000000010000000110000001010000001110000010010000010110000011010000011110000100010000100110000101010000101110000110010000110110000111010000111110001000110001001010001001110001010010001010110001011010001011110001100110001101010001101110001110010001110110001111010001111110010010010110010011010010011110010100110010101010010101110010110110010111010010111110011001110011010110011011010011011110011101010011101110011110110011111010011111110101010110101011110101101110101110110101111110110110111110111011110111111111"); 16 if(n==10) puts("1024 0000000000100000000110000000101000000011100000010010000001011000000110100000011110000010001000001001100000101010000010111000001100100000110110000011101000001111100001000010001100001001010000100111000010100100001010110000101101000010111100001100010000110011000011010100001101110000111001000011101100001111010000111111000100010100010001110001001001000100101100010011010001001111000101001100010101010001010111000101100100010110110001011101000101111100011000110010100011001110001101001000110101100011011010001101111000111001100011101010001110111000111100100011110110001111101000111111100100100110010010101001001011100100110110010011101001001111100101001010011100101010110010101101001010111100101100110010110101001011011100101110110010111101001011111100110011010011001111001101010100110101110011011011001101110100110111110011100111010110011101101001110111100111101010011110111001111101100111111010011111111010101010111010101101101010111110101101011011110101110111010111101101011111110110110111011011111101110111110111101111111111"); 17 if(n==11) puts("2048 00000000000100000000011000000001010000000011100000001001000000010110000000110100000001111000000100010000001001100000010101000000101110000001100100000011011000000111010000001111100000100001000001000110000010010100000100111000001010010000010101100000101101000001011110000011000100000110011000001101010000011011100000111001000001110110000011110100000111111000010000110000100010100001000111000010010010000100101100001001101000010011110000101000100001010011000010101010000101011100001011001000010110110000101110100001011111000011000110000110010100001100111000011010010000110101100001101101000011011110000111000100001110011000011101010000111011100001111001000011110110000111110100001111111000100010010001000101100010001101000100011110001001001100010010101000100101110001001100100010011011000100111010001001111100010100011000101001010001010011100010101001000101010110001010110100010101111000101100110001011010100010110111000101110010001011101100010111101000101111110001100011100011001001000110010110001100110100011001111000110100110001101010100011010111000110110010001101101100011011101000110111110001110010100011100111000111010010001110101100011101101000111011110001111001100011110101000111101110001111100100011111011000111111010001111111100100100101001001001110010010101100100101101001001011110010011001100100110101001001101110010011101100100111101001001111110010100101100101001101001010011110010101001100101010101001010101110010101101100101011101001010111110010110011100101101011001011011010010110111100101110011001011101010010111011100101111011001011111010010111111100110011011001100111010011001111100110100111001101010110011010110100110101111001101101010011011011100110111011001101111010011011111100111001111001110101010011101011100111011011001110111010011101111100111101011001111011010011110111100111110101001111101110011111101100111111101001111111110101010101101010101111010101101110101011101101010111111010110101110101101101101011011111010111011110101111011101011111011010111111110110110111101101110111011011111110111011111101111011111011111111111"); 18 }
G. 天天爱跑步
内存限制:512 MiB 时间限制:2000 ms 标准输入输出
题目类型:传统 评测方式:文本比较
题目描述
输入格式
输出格式
首先想的就是打v暴力,就是程序跟着人跑,但是按折磨跑,看一眼数据范围,一定TLE
然后就要转变思路,按着观察员跑程序,那么一个人对一个观察员在什么状态下可以有贡献呢?当然要:
把这个人要跑的路径分为s(起点)到lca(s,t);和lca到t(终点),然后上行和下行分别维护两个桶(装X写法,实际就是vector数组),用来统计,其实要注意的就是要去重,但我一开始并不知道,就卡了半天;还有就是,以后遇到这种题不要指望着暴力卡常可以ac,不存在的;