-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsledge.cpp
More file actions
70 lines (61 loc) · 1.29 KB
/
sledge.cpp
File metadata and controls
70 lines (61 loc) · 1.29 KB
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
64
65
66
67
68
69
70
/**
* French Australian Regional Informatics Olympiad 2008, Q2
* Ananya Kumar, 2012
* NUS High School
*
* Gets 95/100 points. Additional speed up is needed
* for 100 points.
**/
#include <cstdio>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
#define MAXC 40001
#define MAXK 201
vector<int> neigh[MAXC];
int dp[MAXC][MAXK];
int A[MAXC];
int X[MAXC];
int Y[MAXC];
int R[MAXC];
int C, K;
int main ()
{
scanf("%d %d",&C,&K);
int i, j, k;
for ( i = 0; i < C; i++ ) scanf("%d %d %d %d",&X[i],&Y[i],&R[i],&A[i]);
A[C] = 0;
//Construct the Graph
for ( i = C-1; i >= 0; i-- )
{
for ( j = i+1; j < C; j++ )
{
//If circle i is in circle j connect them and break
if ( (X[i]-X[j])*(X[i]-X[j]) + (Y[i]-Y[j])*(Y[i]-Y[j]) <= R[j]*R[j] )
{
neigh[i].push_back(j);
neigh[j].push_back(i);
break;
}
}
if ( neigh[i].size() == 0 )
{
neigh[i].push_back(C);
neigh[C].push_back(i);
}
}
for ( i = 0; i <= C; i++ ) dp[i][0] = A[i];
for ( i = 1; i <= K; i++ ) //Dynamic Programming
{
for ( j = 0; j <= C; j++ )
{
dp[j][i] = dp[j][i-1];
for ( k = 0; k < neigh[j].size(); k++ ) dp[j][i] = min(dp[j][i],dp[neigh[j][k]][i-1]);
}
}
int ans = 0;
for ( i = 0; i <= C; i++ ) ans = max(ans,A[i]-dp[i][K]);
printf("%d\n",ans);
return 0;
}