Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

简单DP,0MS

Posted by LXY5201314 at 2018-04-17 18:03:57 on Problem 1260
#include<cstdio>
#include<cstring>
#include<algorithm>
#define inf 9999999
using namespace std;
struct kk
{
    int a;
    int p;
    int sum;
}r[200];
int dp[200];
int main()
{
    int t,n,i,j;
    scanf("%d",&t);
    while(t--)
    {
        memset(dp,inf,sizeof(dp));
        scanf("%d",&n);
        r[0].sum=0;
        for(i=1;i<=n;i++)
        {
            scanf("%d%d",&r[i].a,&r[i].p);
            r[i].sum=r[i-1].sum+r[i].a;
        }
        dp[0]=0;
        for(i=1;i<=n;i++)
            for(j=0;j<i;j++)
                dp[i]=min(dp[i],(r[i].sum-r[j].sum+10)*r[i].p+dp[j]);
        printf("%d\n",dp[n]);
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator