-
Notifications
You must be signed in to change notification settings - Fork 0
/
10306.cpp
63 lines (46 loc) · 853 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <bits/stdc++.h>
using namespace std;
int S, M;
int dp[301][301][40];
const int INF = 100000;
struct Coin
{
int x;
int y;
Coin(int _x, int _y) : x(_x), y(_y){}
};
vector<Coin> coins;
int go(int x, int y, int pos)
{
if (x * x + y * y == S * S)
return 0;
if (x * x + y * y > S * S || pos == M)
return INF;
int &ans = dp[x][y][pos];
if (ans != -1)
return ans;
ans = min(1 + go(x + coins[pos].x, y + coins[pos].y, pos)
, go(x, y, pos + 1));
return ans;
}
int main()
{
ios_base::sync_with_stdio(false);
int n;
cin >> n;
while (n--)
{
cin >> M >> S;
memset(dp, -1, sizeof dp);
coins.clear();
for (int i = 0; i < M; i++)
{
int c, v;
cin >> c >> v;
coins.push_back(Coin(c, v));
}
int ans = go(0, 0, 0);
cout << (ans == INF ? "not possible\n" : to_string(ans) + "\n");
}
return 0;
}