zoukankan      html  css  js  c++  java
  • poj1260

    思路:dp

         f[i][j]表示前i个总共买了j个总共要付的最小费用。。。

         f[i][j] = min(f[i -1][k] + (j-k+10)*value[i]);  k<=sum[i-1]

     1 /*
     2  State:Accepted
     3  Time:2013.3.2
     4 */
     5 
     6 #include <iostream>
     7 #include <cstring>
     8 #include <string>
     9 #include <fstream>
    10 #include <cstdlib>
    11 #include <cstdio>
    12 #include <algorithm>
    13 #include <cmath>
    14 int dp[200] , sum[200] , p[200] ,test , n ;
    15 
    16 int min(int x , int y){
    17       return x < y? x : y;
    18 }
    19 
    20 void solve(){
    21      scanf("%d",&n);
    22      memset(sum , 0 ,sizeof(sum));
    23      for (int i = 1; i <= n; ++i)
    24        {
    25            scanf("%d%d",&sum[i] , &p[i]);
    26            sum[i] += sum[i - 1];
    27        }
    28      for (int i = 1; i <= n; ++i){
    29         dp[i] = 1000000000;
    30         for (int j = 0; j < i; ++j)
    31              dp[i] = min(dp[i] , dp[j] + (sum[i] - sum[j] + 10) * p[i]);
    32      }
    33      printf("%d\n",dp[n]);
    34      
    35 }
    36 
    37 int main(){
    38      freopen("poj1260.in","r",stdin);
    39      freopen("poj1260.out","w",stdout);
    40      scanf("%d",&test);
    41      while ( test -- ){
    42            solve();
    43      }
    44 }
  • 相关阅读:
    python note 30 断点续传
    python note 29 线程创建
    python note 28 socketserver
    python note 27 粘包
    python note 26 socket
    python note 25 约束
    Sed 用法
    python note 24 反射
    python note 23 组合
    python note 22 面向对象成员
  • 原文地址:https://www.cnblogs.com/yzcstc/p/2977676.html
Copyright © 2011-2022 走看看