Description
Jia Jia has recently been fascinated by a similar to the virtual life of the online game. In the game, Allison is the head of a tour, he needs to arrange customers to stay in the hotel. The hotel has given the best tours a limited number of rooms. Each room has a different occupancy and price (the price is the total price of the room, not everyone pays). Allison decided to find the minimum cost and arrange for the people who are traveling to live here. But he was confronted with a problem: two different genders could not live in the same room unless they were married, and if a couple lived together, no one else would be able to live there. You don't have to have all the couples living alone. This means:
1. Give you some room to tell you the capacity and price of these rooms
2. Arrange for a certain number of people to stay in the hotel and meet:
A. People of different genders cannot live together if they are not married.
B. If a couple lives together, the room cannot arrange for other people to go in.
you write a program that helps Allison find the minimum cost of arranging these people to travel to the hotel.
format
Input Format
The first line has 4 integer m,f,r,c separated by spaces, representing the number of males travelling, the number of females travelling, the number of rooms in the hotel, and how many of these men and women are married. Note that everyone who is not single is travelling with his/her only wife/husband.
Next there is a row of R, each of which describes a room. Each line has two integer bi,pi, each representing the number and price of each house (no matter how many people live, the price of the room does not change).
for 30% of data,0<=m,f,r<=50;
for 100% of data, 0<=m,f,r<=300,0<=c<=min (m,f), 0<=bi,pi<=10.
output Format
output the minimum cost required to order a room for the person traveling. If there is no such arrangement, please output "impossible" instead.
Sample Input
2 1 3 1
3 5
2 Ten
2 4
Sample Output
9
Limit
5 seconds for each test point
Oibh Proposition Group provides by month shadow
Resolution: Dp[l][i][j][k]:l: the first L room. I:i a man. J:j a woman. K=0 Or1, indicating whether there are couples. Apparently couples have a couple in a house (I don't think it should be a problem), otherwise it's not optimal.
#include <iostream>#include<cstdio>#include<cmath>#include<cstring>#include<algorithm>#include<cstdlib>using namespacestd;intm,f,r,c;intb[ -],p[ -];intdp[301][301][301][2];intMain () {CIN>> m >> F >> R >>C; for(intI=1; i<=r; i++) cin >> B[i] >>P[i]; Memset (DP,127,sizeof(DP)); inttot=dp[0][0][0][0]; dp[0][0][0][0]=0; for(intL=1; l<=r; l++) for(intI=0; i<=m; i++) for(intj=0; j<=f; J + +) { if(b[l]>=2&& j>=1&& i>=1) dp[l][i][j][1]=min (dp[l-1][i-1][j-1][0]+p[l],dp[l-1][i][j][1]); dp[l][i][j][0]=min (dp[l-1][i][j][0],dp[l][i][j][0]); for(into=1; o<=b[l]; o++) { if(i-o>=0) {dp[l][i][j][0]=min (dp[l-1][i-o][j][0]+p[l],dp[l][i][j][0]); dp[l][i][j][1]=min (dp[l-1][i][j][1],dp[l-1][i-o][j][1]+P[l]); } if(j-o>=0) {dp[l][i][j][0]=min (dp[l-1][i][j-o][0]+p[l],dp[l][i][j][0]); dp[l][i][j][1]=min (dp[l-1][i][j-o][1]+p[l],dp[l][i][j][1]); } } } intAns=min (dp[r][m][f][0],dp[r][m][f][1]); if(Ans==tot) cout <<"Impossible"<<Endl; Elsecout <<ans; return 0;}
Back Gear | Plain online game