poj1260

dp

View Code
   
     
#include < iostream >
#include
< cstdio >
#include
< cstdlib >
#include
< cstring >
using namespace std;

#define maxn 106

struct Pearl
{
int num, p;
}pearl[maxn];

int n, f[maxn];

void input()
{
scanf(
" %d " , & n);
for ( int i = 0 ; i < n; i ++ )
scanf(
" %d%d " , & pearl[i].num, & pearl[i].p);
}

void work()
{
int sum;
f[n]
= 0 ;
for ( int i = n - 1 ; i >= 0 ; i -- )
{
sum
= 0 ;
f[i]
= 0x3f3f3f3f ;
for ( int j = i; j < n; j ++ )
{
sum
+= pearl[j].num;
f[i]
= min(f[i], (sum + 10 ) * pearl[j].p + f[j + 1 ]);
}
}
}

int main()
{
// freopen("t.txt", "r", stdin);
int t;
scanf(
" %d " , & t);
while (t -- )
{
input();
work();
printf(
" %d\n " , f[ 0 ]);
}
return 0 ;
}

你可能感兴趣的:(poj)