-
Notifications
You must be signed in to change notification settings - Fork 3
/
10306.cpp
38 lines (32 loc) · 940 Bytes
/
10306.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>
#include <cmath>
#define ll long long
#define inf 9999999
#define sq(a) (a*a)
using namespace std;
int dp[301][301], values[41][2], target, ntypes;
int main() {
int n; cin >> n;
while (n--) {
cin >> ntypes >> target;
for (int i = 0; i < ntypes; i++) {
cin >> values[i][0] >> values[i][1];
}
for (int i = 0; i <= target; i++)
for (int j = 0; j <= target; j++)
dp[i][j] = inf;
dp[0][0] = 0;
for (int c = 0; c < ntypes; c++)
for (int i = values[c][0]; i <= target; i++)
for (int j = values[c][1]; j <= target; j++)
dp[i][j] = min(dp[i][j], 1 + dp[i-values[c][0]][j-values[c][1]]);
int m = inf;
for (int i = 0; i <= target; i++)
for (int j = 0; j <= target; j++)
if (sq(i) + sq(j) == sq(target))
m = min(m, dp[i][j]);
if (m == inf) cout << "not possible" << endl;
else cout << m << endl;
}
return 0;
}