水的不能再水了,合理利用下前缀和
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define MAX 107
using namespace std;
int t,n;
int a[MAX];
int c[MAX];
int dp[MAX];
int sum[MAX];
int main ( )
{
scanf ( "%d" , &t );
while ( t-- )
{
scanf ( "%d" , &n );
sum[0] = 0;
for ( int i = 1 ; i <= n ; i++ )
{
scanf ( "%d%d" , &a[i] , &c[i] );
sum[i] = sum[i-1] + a[i];
}
memset ( dp , 0x3f , sizeof ( dp ) );
dp[0] = 0;
for ( int i = 1 ; i <= n ; i++ )
for ( int j = 0 ; j < i ; j++ )
dp[i] = min ( dp[i] , dp[j] + c[i]*(sum[i]-sum[j]+10) );
printf ( "%d\n" , dp[n] );
}
}