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 }
  • 相关阅读:
    Java 8特性
    11成最多体积的容器
    MySQL数据库理解
    java范型
    ArrayList源码分析
    1.面试题
    jvm简单了解
    121. 买卖股票的最佳时机
    有效的括号
    java如何判断一个字符串中某个字符有几个
  • 原文地址:https://www.cnblogs.com/yzcstc/p/2977676.html
Copyright © 2011-2022 走看看