2014多校训练第十场(最大权闭合问题)
2014-09-03 16:39
225 查看
最后一场做的很消极
Total Submission(s): 578 Accepted Submission(s): 237
Problem Description
Dragon is watching NBA. He loves James and Miami Heat.
Here's an introduction of basketball game:http://en.wikipedia.org/wiki/Basketball. However the game in Dragon's version is much easier:
"There's two teams fight for the winner. The only way to gain scores is to throw the basketball into the basket. Each time after throwing into the basket, the score gained by the team is 1, 2 or 3. However due to the uncertain factors in the game, it’s hard
to predict which team will get the next goal".
Dragon is a crazy fan of Miami Heat so that after each throw, he will write down the difference between two team's score regardless of which team keeping ahead. For example, if Heat's score is 15 and the opposite team's score is 20, Dragon will write down 5.
On the contrary, if Heat has 20 points and the opposite team has 15 points, Dragon will still write down 5.
Several days after the game, Dragon finds out the paper with his record, but he forgets the result of the game. It's also fun to look though the differences without knowing who lead the game, for there are so many uncertain! Dragon loves uncertain, and he wants
to know how many results could the game has gone?
Input
The first line of input contains only one integer T, the number of test cases. Following T blocks, each block describe one test case.
For each test case, the first line contains only one integer N(N<=100000), which means the number of records on the paper. Then there comes a line with N integers (a1, a2, a3, ... , an). ai means
the number of i-th record.
Output
Each output should occupy one line. Each line should start with "Case #i: ", with i implying the case number. Then for each case just puts an integer, implying the number of result could the game has gone.
Sample Input
Sample Output
思路:首先如果相邻的分差的差大于3或者分差相等但不等于1这两种情况是不可能出现的,因为分差已经确定,所以最后比分的情况就是有多少种和,只用1->2和2->1这两种情况会增加比分,所以找出有多少种这样的,那么最后的情况就是cnt+1中,可以手动模拟一下
Total Submission(s): 388 Accepted Submission(s): 225
Problem Description
There's a company with several projects to be done. Finish a project will get you profits. However, there are some technical problems for some specific projects. To solve the problem, the manager will train his employee which may cost his budget. There may
be dependencies between technical problems, for example, A requires B means you need to solve problem B before solving problem A. If A requires B and B requires A, it means that you should solve them at the same time. You can select which problems to be solved
and how to solve them freely before finish your projects. Can you tell me the maximum profit?
Input
The first line of the input is a single integer T(<=100) which is the number of test cases.
Each test case contains a line with two integer n(<=20) and m(<=50) which is the number of project to select to complete and the number of technical problem.
Then a line with n integers. The i-th integer(<=1000) means the profit of complete the i-th project.
Then a line with m integers. The i-th integer(<=1000) means the cost of training to solve the i-th technical problem.
Then n lines. Each line contains some integers. The first integer k is the number of technical problems, followed by k integers implying the technical problems need to solve for the i-th project.
After that, there are m lines with each line contains m integers. If the i-th row of the j-th column is 1, it means that you need to solve the i-th problem before solve the j-th problem. Otherwise the i-th row of the j-th column is 0.
Output
For each test case, please output a line which is "Case #X: Y ", X means the number of the test case and Y means the the maximum profit.
Sample Input
Sample Output
最大权闭合问题(起点在重点也必须在集合中),这里项目为正权,问题为负权,对于问题的顺序,A->B则加一条(A,B,INF)的边,这样如果两个任务要同时完成,因为容量为INF所以可以同时满足
A simple dynamic programming problem
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 578 Accepted Submission(s): 237
Problem Description
Dragon is watching NBA. He loves James and Miami Heat.
Here's an introduction of basketball game:http://en.wikipedia.org/wiki/Basketball. However the game in Dragon's version is much easier:
"There's two teams fight for the winner. The only way to gain scores is to throw the basketball into the basket. Each time after throwing into the basket, the score gained by the team is 1, 2 or 3. However due to the uncertain factors in the game, it’s hard
to predict which team will get the next goal".
Dragon is a crazy fan of Miami Heat so that after each throw, he will write down the difference between two team's score regardless of which team keeping ahead. For example, if Heat's score is 15 and the opposite team's score is 20, Dragon will write down 5.
On the contrary, if Heat has 20 points and the opposite team has 15 points, Dragon will still write down 5.
Several days after the game, Dragon finds out the paper with his record, but he forgets the result of the game. It's also fun to look though the differences without knowing who lead the game, for there are so many uncertain! Dragon loves uncertain, and he wants
to know how many results could the game has gone?
Input
The first line of input contains only one integer T, the number of test cases. Following T blocks, each block describe one test case.
For each test case, the first line contains only one integer N(N<=100000), which means the number of records on the paper. Then there comes a line with N integers (a1, a2, a3, ... , an). ai means
the number of i-th record.
Output
Each output should occupy one line. Each line should start with "Case #i: ", with i implying the case number. Then for each case just puts an integer, implying the number of result could the game has gone.
Sample Input
2 2 2 3 4 1 3 5 7
Sample Output
Case #1: 2 Case #2: 2
思路:首先如果相邻的分差的差大于3或者分差相等但不等于1这两种情况是不可能出现的,因为分差已经确定,所以最后比分的情况就是有多少种和,只用1->2和2->1这两种情况会增加比分,所以找出有多少种这样的,那么最后的情况就是cnt+1中,可以手动模拟一下
#include<iostream> #include<cstdio> #include<string> #include<cstring> #include<vector> #include<cmath> #include<queue> #include<stack> #include<map> #include<set> #include<algorithm> using namespace std; const int maxn=100010; int n,d[maxn]; int main() { int T,cas=1; scanf("%d",&T); while(T--) { scanf("%d",&n); memset(d,0,sizeof(d)); for(int i=1;i<=n;i++)scanf("%d",&d[i]); bool flag=1; int cnt=0; for(int i=1;i<=n;i++) { if(d[i]==d[i-1]&&d[i]!=1||abs(d[i]-d[i-1])>3) { flag=0; break; } if(d[i]*d[i-1]==2)cnt++; } printf("Case #%d: ",cas++); if(!flag)printf("0"); else if(d ==0)printf("%d",cnt+1); else printf("%d",2*(cnt+1)); printf("\n"); } return 0; }
A simple brute force problem.
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 388 Accepted Submission(s): 225
Problem Description
There's a company with several projects to be done. Finish a project will get you profits. However, there are some technical problems for some specific projects. To solve the problem, the manager will train his employee which may cost his budget. There may
be dependencies between technical problems, for example, A requires B means you need to solve problem B before solving problem A. If A requires B and B requires A, it means that you should solve them at the same time. You can select which problems to be solved
and how to solve them freely before finish your projects. Can you tell me the maximum profit?
Input
The first line of the input is a single integer T(<=100) which is the number of test cases.
Each test case contains a line with two integer n(<=20) and m(<=50) which is the number of project to select to complete and the number of technical problem.
Then a line with n integers. The i-th integer(<=1000) means the profit of complete the i-th project.
Then a line with m integers. The i-th integer(<=1000) means the cost of training to solve the i-th technical problem.
Then n lines. Each line contains some integers. The first integer k is the number of technical problems, followed by k integers implying the technical problems need to solve for the i-th project.
After that, there are m lines with each line contains m integers. If the i-th row of the j-th column is 1, it means that you need to solve the i-th problem before solve the j-th problem. Otherwise the i-th row of the j-th column is 0.
Output
For each test case, please output a line which is "Case #X: Y ", X means the number of the test case and Y means the the maximum profit.
Sample Input
4 2 3 10 10 6 6 6 2 0 1 2 1 2 0 1 0 1 0 0 0 0 0 2 3 10 10 8 10 6 1 0 1 2 0 1 0 1 0 0 0 0 0 2 3 10 10 8 10 6 1 0 1 2 0 1 0 0 0 0 0 0 0 2 3 10 10 8 10 6 1 0 1 2 0 0 0 1 0 0 0 0 0
Sample Output
Case #1: 2 Case #2: 4 Case #3: 4 Case #4: 6
最大权闭合问题(起点在重点也必须在集合中),这里项目为正权,问题为负权,对于问题的顺序,A->B则加一条(A,B,INF)的边,这样如果两个任务要同时完成,因为容量为INF所以可以同时满足
、#include<iostream> #include<cstdio> #include<string> #include<cstring> #include<vector> #include<cmath> #include<queue> #include<stack> #include<map> #include<set> #include<algorithm> using namespace std; const int maxn=10000; const int INF=1000000000; struct node { int v,f,next; }edge[maxn]; int head[maxn],pre[maxn],dis[maxn],vis[maxn],cur[maxn],gap[maxn]; int n,m,s,t,num,nn; void add_edge(int u,int v,int f) { edge[num].v=v; edge[num].next=head[u]; edge[num].f=f; head[u]=num++; edge[num].v=u; edge[num].next=head[v]; edge[num].f=0; head[v]=num++; } int SAP(int s,int t) { for(int i=0;i<=nn;i++) { cur[i]=head[i]; gap[i]=dis[i]=0; } int u; int flow=0,aug=INF; gap[s]=nn; u=pre[s]=s; bool flag; while(dis[s]<nn) { flag=0; for(int &j=cur[u];j!=-1;j=edge[j].next) { int v=edge[j].v; if(edge[j].f>0&&dis[u]==dis[v]+1) { flag=1; if(edge[j].f<aug) aug=edge[j].f; pre[v]=u; u=v; if(u==t) { flow+=aug; while(u!=s) { u=pre[u]; edge[cur[u]].f-=aug; edge[cur[u]^1].f+=aug; } aug=INF; } break; } } if(flag) continue; int mindis=nn; for(int j=head[u];j!=-1;j=edge[j].next) { int v=edge[j].v; if(dis[v]<mindis&&edge[j].f>0) { mindis=dis[v]; cur[u]=j; } } if((--gap[dis[u]])==0) break; gap[dis[u]=mindis+1]++; u=pre[u]; } return flow; } int main() { int T,x,cas=1; scanf("%d",&T); while(T--) { scanf("%d%d",&n,&m); s=num=0,t=n+m+1,nn=t+1; int sum=0,val; memset(head,-1,sizeof(head)); for(int i=1;i<=n;i++) { scanf("%d",&val); add_edge(s,i,val); sum+=val; } for(int i=1;i<=m;i++) { scanf("%d",&val); add_edge(i+n,t,val); } for(int i=1;i<=n;i++) { int k; scanf("%d",&k); for(int j=1;j<=k;j++) { scanf("%d",&val); add_edge(i,n+val+1,INF); } } for(int i=1;i<=m;i++) for(int j=1;j<=m;j++) { scanf("%d",&val); if(val)add_edge(n+i,n+j,INF); } int flow=SAP(s,t); printf("Case #%d: %d\n",cas++,sum-flow); } return 0; }
相关文章推荐
- 2014多校联合第十场A题||hdu 4971 最小割定理在最大权闭合图上的应用
- 2016多校训练hdu5855---最大权闭合图
- 线性规划与网络流24题 2太空飞行计划问题 最大权闭合图问题(不懂) nefu 476
- Wiki 1233(太空飞行计划问题-最大权闭合子图)
- hdu 4915 Parenthese sequence(模拟)2014多校训练第5场
- hdu 4939 Stupid Tower Defense(DP)2014多校训练第7场
- 2014多校3(1002)hdu4888(最大流(dinic))
- 多校第16场 HDU3996 Gold Mine (最大权闭合图)
- hdu 4965 Fast Matrix Calculation(矩阵快速幂)2014多校训练第9场
- hdu 4920 Matrix multiplication(矩阵相乘)2014多校训练第5场
- hdu 4901 The Romantic Hero(计数dp)2014多校训练第4场1005
- hdu 4941 Magical Forest(STL之map应用)2014多校训练第7场
- Wiki 1233(太空飞行计划问题-最大权闭合子图)
- HDU 4869 Turn the pokers (2014多校联合训练第一场1009) 解题报告(维护区间 + 组合数)
- 2014湘潭全国邀请赛I题 Intervals /POJ 3680 / 在限制次数下取有权区间使权最大/小问题(费用流)
- hdu 4911 Inversion(归并排序求逆序对数)2014多校训练第5场
- 线性规划与网络流24题 2太空飞行计划问题 最大权闭合图问题(不懂) nefu 476
- 2014湘潭全国邀请赛I题 Intervals /POJ 3680 / 在限制次数下取有权区间使权最大/小问题(费用流)
- 2014多校联合训练1 A.Couple doubi
- hdu 4927 Series 1(高精度) 2014多校训练第6场