Time limit: 5000ms single point time limit: 1000ms memory limit: 256MB description
Small Hi's dorm downstairs there is an area for stopping bicycles. Usually the bikes are parked very cluttered, so the building is going to buy a row of bike racks for parking. Bike racks generally have p slots, each of which can be parked on both sides of the bike, but one slot can only be parked on the side of the bike. In addition, stopping into a bicycle can result in the inability to stop in a number of slots near the side of the bike.
After investigation, the students in this dormitory building owned n A-type bicycles, M-type B bikes and K-type C bikes. Where a type of bicycle will cause this side of the left and right one slot can not be used, B-type bicycle will cause the side of the left and right 2 slots can not be used, C-type bicycle will cause the side of the left and right 3 slots can not be used.
Now given N, M and K, Lou Long wants to know how much p is at least to stop all bicycles.
As shown, p at least 7 can be stored under 2 A-type, 1 B-Type and 2-type C.
Input
Each input file contains multiple sets of test data, the first behavior of each input file is an integer q, which represents the number of groups of test data.
Each set of test data is 3 integers n, m, and K, meaning as described earlier.
For 20% of data, meet 0<=n, M, k<=2,q=100
For 40% of data, meet 0<=n, M, k<=50,q=100
For 100% of data, meet 0<=n, M, k<=50,1<=q<=100000
Output
For each set of test data, output an integer p indicating the minimum slot required for the bike rack.
-
-
Sample input
-
-
42 1 21 0 02 0 21 2 2
-
-
Sample output
-
7157
AC Code:
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespacestd;Const intinf=1e8+1;intdp[ the][ the][ the][4][4][4],ans;intGET_DP () {memset (Dp,inf,sizeof(DP)); dp[1][0][0][0][0][3]=1; dp[0][1][0][1][0][3]=1; dp[0][0][1][2][0][3]=1; for(intI=0; i<= -; i++) { for(intj=0; j<= -; j + +) { for(intk=0; k<= -; k++) { for(intLi=0;li<3; li++) { for(intlj=0;lj<3; lj++) { for(intlk=1; lk<=3; lk++) { if(dp[i][j][k][li][lj][lk]!=inf)//i a a,j b,k C,li is the top type of the long column, LJ is short, LK is long and short, { for(intAd=0;ad<3; ad++) { intfi=i,fj=j,fk=K; if(ad==0) fi++; if(ad==1) fj++; if(ad==2) fk++; intFlk=lk+max (LI,AD) +2; if(flk>3) flk=3; DP[FI][FJ][FK][AD][LJ][FLK]=min (Dp[fi][fj][fk][ad][lj][flk],dp[i][j][k][li][lj][lk]+max (LI,AD) +2); Flk=max (Max (LJ,AD) +2-lk,1); if(flk>3) flk=3; DP[FI][FJ][FK][AD][LI][FLK]=min (dp[fi][fj][fk][ad][li][flk],dp[i][j][k][li][lj][lk]+flk); } } } } } } } }}intMain () {intt,n,m,l; scanf ("%d",&t); GET_DP (); dp[0][0][0][0][0][1]=0; while(t--) {scanf ("%d%d%d",&n,&m,&l); Ans=inf; for(intI=0;i<3; i++) { for(intj=0;j<3; j + +) { for(intk=1; k<=3; k++) {ans=min (ans,dp[n][m][l][i][j][k]); }}} printf ("%d\n", ans); } return 0;}
hihocoder-1274 Bike racks (high-dimensional DP)