Time limit: 4000ms, special time limit:10000ms, Memory Limit:65536KB |
Total Submit users: One, Accepted users: 9 |
problem 13240: No Special Judgement |
Problem description |
A Long art Gallery has 2N rooms. The gallery is laid out as N rows of 2 rooms side-by-side. Doors Connect all adjacent rooms (North-south and east-west, but not diagonally). The curator has been told that she must close off K of the rooms because of staffing cuts. Visitors must be able to enter using at least one of the the The Rooms, gallery proceed the through, and exit from at least one of the rooms at the other end. Therefore, the curator must not close off any of the rooms that would block passage through the gallery. That's, the curator may not be block off rooms in the same row or both rooms in adjacent rows that touch diagonally. Furthermore, she had determined how much value each of the have to the general public, and now she wants to close off those K Rooms that leave the most value available to the public, without blocking passage through the gallery. |
Input |
Input would consist of multiple problem instances (galleries). Each problem instance would begin with a line containing the integers N and K, where 3≤n≤200 gives the number of rows, And 0≤k≤n gives the number of rooms that must is closed off. This was followed by N rows of the integers, giving the values of the the both rooms in that row. Each of the value v satisfies 0≤v≤100. A Line containing 0 0 would follow the last gallery. |
Output |
For each gallery, the output of the amount of value is optimally receive, one line per gallery. |
Sample Input |
6 43 12 11 21 33 30 04 33 41 11 15 610 57 84 93 75 97 210 30 103 26 37 90 0 |
Sample Output |
1717102 |
Problem Source |
ACM-ICPC North America Qualifier 2014 |
I'm still very weak ...
DP[I][J][K]: First I row at State J, the maximum value after the K-room is turned off
Of course some k are not visited in certain States, so a very small value is assigned at this time. This will not affect the results.
J is a state of 3. 0 for I row two can not be taken. 1 To turn off I line left that room, 2 for off I line right that room
#include <map> #include <string> #include <cstring> #include <cstdio> #include <cstdlib># include<cmath> #include <queue> #include <vector> #include <iostream> #include <algorithm > #include <bitset> #include <climits> #include <list> #include <iomanip> #include <stack > #include <set>using namespace std;int dp[210][3][210],k,n,g[210][2];int work () {for (int i=0;i<3;i++) fill (dp[0][i],dp[0][i]+k+1,int_min);DP [0][0][0]=g[0][0]+g[0][1];dp [0][1][1]=g[0][1];dp [0][2][1]=g[0][0];for (INT I=1 ; i<n;i++) for (int j=0;j<=k;j++) {Dp[i][0][j]=max (Dp[i-1][0][j],max (Dp[i-1][1][j],dp[i-1][2][j])) +g[i][0]+g[ I][1];if (j==0) Dp[i][1][j]=dp[i][2][j]=int_min;else{dp[i][1][j]=max (dp[i-1][0][j-1],dp[i-1][1][j-1]) +g[i][1];dp I [2] [J]=max (Dp[i-1][0][j-1],dp[i-1][2][j-1]) +g[i][0];}} Return Max (Dp[n-1][0][k],max (dp[n-1][1][k],dp[n-1][2][k));} int main () {while (cin>>n>>k) {if (n==0&&k==0) break;for (int. i=0;i<n;i++) for (int j=0;j<2; j + +) Cin>>g[i][j];cout<<work () <<endl;}}
Narrow Art Gallery