C - All Green
Time limit : 2sec / Memory limit : 1024MB
Score : 300 points
Problem Statement
A programming competition site AtCode provides algorithmic problems. Each problem is allocated a score based on its difficulty. Currently, for each integer i between 1 and D (inclusive), there are pi problems with a score of 100i points. These p1+…+pD problems are all of the problems available on AtCode.
A user of AtCode has a value called total score. The total score of a user is the sum of the following two elements:
- Base score: the sum of the scores of all problems solved by the user.
- Perfect bonuses: when a user solves all problems with a score of 100i points, he/she earns the perfect bonus of ci points, aside from the base score (1≤i≤D).
Takahashi, who is the new user of AtCode, has not solved any problem. His objective is to have a total score of G or more points. At least how many problems does he need to solve for this objective?
Constraints
- 1≤D≤10
- 1≤pi≤100
- 100≤ci≤106
- 100≤G
- All values in input are integers.
- ci and G are all multiples of 100.
- It is possible to have a total score of G or more points.
Input
Input is given from Standard Input in the following format:
D G p1 c1 : pD cD
Output
Print the minimum number of problems that needs to be solved in order to have a total score of G or more points. Note that this objective is always achievable (see Constraints).
Sample Input 1
Copy
2 700 3 500 5 800
Sample Output 1
Copy
3
In this case, there are three problems each with 100 points and five problems each with 200 points. The perfect bonus for solving all the 100-point problems is 500points, and the perfect bonus for solving all the 200-point problems is 800 points. Takahashi's objective is to have a total score of 700 points or more.
One way to achieve this objective is to solve four 200-point problems and earn a base score of 800 points. However, if we solve three 100-point problems, we can earn the perfect bonus of 500 points in addition to the base score of 300 points, for a total score of 800 points, and we can achieve the objective with fewer problems.
Sample Input 2
Copy
2 2000 3 500 5 800
Sample Output 2
Copy
7
This case is similar to Sample Input 1, but the Takahashi's objective this time is 2000 points or more. In this case, we inevitably need to solve all five 200-point problems, and by solving two 100-point problems additionally we have the total score of 2000 points.
Sample Input 3
Copy
2 400 3 500 5 800
Sample Output 3
Copy
2
This case is again similar to Sample Input 1, but the Takahashi's objective this time is 400 points or more. In this case, we only need to solve two 200-point problems to achieve the objective.
Sample Input 4
Copy
5 25000 20 1000 40 1000 50 1000 30 1000 1 1000
Sample Output 4
Copy
66
There is only one 500-point problem, but the perfect bonus can be earned even in such a case.、
题意:给出你d个题目,然后和一个需要达到的分数G,对于每个题目,第i个题目做一道会获得 i * 100的分数,如果
做到p[i]的数目的话,就可以获得额外的分数c[i]。每道题目,只能做一套
思路: 因为最多只有10个题目,那我们可以先暴力每个题目做与不做,就是2^10,如果有剩下的分数,你就可以用
贪心,倒着取题目,来做,然后对于每次的题目数取个min
代码如下:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200;
int d,gg,c[maxn],p[maxn],vis[maxn];
struct node {
int c,p;
int id,s;
} g[maxn];
int getans() {
int ans = 0;
int sum = 0;
int G = gg;
for(int i = 1; i <= d; i++) {
if(vis[i]) G -= (g[i].p * 100 * i + g[i].c),ans += g[i].p;
}
for(int i = d; i >= 1; i--) {
if(!vis[i]) {
if(G > 0) {
if(G >= g[i].p * 100 * i) {
ans += g[i].p;
G -= (g[i].p * 100 * i + g[i].c);
} else {
ans += G / (i * 100);
G -= 100 * i * (G / (i * 100));
}
}
}
}
if(G <= 0) return ans;
else return 1e9;
}
int main() {
while(cin >> d >> gg) {
int ans = 1e9;
for(int i = 1; i <= d; i++)
cin >> g[i].p >> g[i].c,g[i].id = i;
for(int i = 0; i < (1 << d); i++) {
for(int j = 1; j <= d; j++) {
if(1 & (i >> (j - 1))) vis[j] = 1;
else vis[j] = 0;
}
int sum = getans();
ans = min(ans,sum);
}
cout << ans << endl;
}
return 0;
}