-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy path1260.cpp
49 lines (46 loc) · 852 Bytes
/
1260.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
#include <stdio.h>
#define inf 99999999
int mem[105][105];
int a[105], p[105], sum[105], c;
int f(int x, int y)
{
if (mem[x][y] != inf) return mem[x][y];
if (x >= c)
{
if (x == y) return 0;
else return inf;
}
int buy = 0, skip = 0;
buy = (10+sum[x]-sum[y]+a[x])*p[x]+f(x+1, x+1);
skip = f(x+1, y);
if (buy < skip) mem[x][y] = buy;
else mem[x][y] = skip;
return mem[x][y];
}
int main()
{
int testcase;
scanf("%d", &testcase);
while (testcase > 0)
{
testcase--;
scanf("%d", &c);
int i, j;
for (i = 0; i <= c; i++)
{
a[i] = p[i] = sum[i] = 0;
for (j = 0; j <= c; j++)
{
mem[i][j] = inf;
}
}
for (i = 0; i < c; i++)
{
scanf("%d %d", a+i, p+i);
if (i > 0) sum[i] = a[i-1]+sum[i-1];
else sum[i] = 0;
}
printf("%d\n", f(0, 0));
}
return 0;
}