zoukankan      html  css  js  c++  java
  • USACO 3.1.2 Score Inflation 题解

    【算法】动态规划  【难度】★☆☆☆☆


     很经典的完全背包问题

    详见dd的背包九讲

    View Code
     1 /*
    2 ID: wsc5001
    3 LANG: C
    4 TASK: inflate
    5 */
    6 #include <stdio.h>
    7 #include <stdlib.h>
    8 int c,v;
    9 int s[10000+10];
    10 int t[10000+10];
    11 int f[10000+10];
    12 int bigger(int a,int b)
    13 {
    14 return a>b?a:b;
    15 }
    16 int main()
    17 {
    18 freopen("inflate.in","r",stdin);
    19 freopen("inflate.out","w",stdout);
    20 scanf("%d%d",&v,&c);
    21 int i,j,k,e;
    22 for (i=1;i<=c;i++)
    23 scanf("%d%d",&s[i],&t[i]);
    24 for (i=0;i<=v+1;i++)//初始化
    25 f[i]=0;
    26 for (i=1;i<=c;i++)
    27 for (j=t[i];j<=v;j++)
    28 f[j]=bigger(f[j],f[j-t[i]]+s[i]);
    29 printf("%d\n",f[v]);
    30 //system("pause");
    31 fclose(stdin);
    32 fclose(stdout);
    33 }



  • 相关阅读:
    MVC ActionResult JsonResult
    xml文件
    使用socket实现聊天功能
    使用多线程完成Socket
    Socket编程
    U1总结
    多线程
    IO
    单例模式
    日期
  • 原文地址:https://www.cnblogs.com/loveidea/p/2416942.html
Copyright © 2011-2022 走看看