-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10306.cpp
More file actions
49 lines (45 loc) · 909 Bytes
/
Copy path10306.cpp
File metadata and controls
49 lines (45 loc) · 909 Bytes
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
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#define MAX 43
#define LIM 303
#define INF 1<<22
int m,gol;
int cashA[ MAX ],cashB[ MAX ];
int dp[ LIM ][ LIM ];
int mod( int x , int y )
{
if( ( x * x ) + ( y * y ) == gol )
return 0;
if( ( x * x ) + ( y * y ) > gol )
return INF;
if( dp[ x ][ y ] != -1 )
return dp[ x ][ y ];
int men = INF ;
for( int i = 0 ; i < m ; ++i )
men = min( men , mod( x + cashA[ i ] , y + cashB[i] ) + 1 );
return dp[ x ][ y ] = men;
}
int main()
{
int t;
scanf("%d",&t);
while( t-- )
{
int s;
scanf("%d %d",&m,&s);
for( int i = 0 ; i < m ; ++i )
{
scanf("%d %d", &cashA[i] , &cashB[i] );
}
gol = s * s;
memset( dp , -1 , sizeof dp );
int res = mod( 0 , 0 );
if( res == INF )
printf("not possible\n");
else
printf("%d\n", res );
}
return 0 ;
}