zoukankan      html  css  js  c++  java
  • day 2 上午 挂饰 背包

     1 #include<iostream>
     2 #include<algorithm>
     3 #include<cstring>
     4 #include<cstdio>
     5 using namespace std;
     6 const int maxn=2010;
     7 struct node 
     8 {
     9     int a,b;
    10 }gua[maxn];
    11 int dp[maxn][maxn];
    12 int n;
    13 bool cmp(node a,node b)
    14 {
    15     return a.a>b.a;
    16 }
    17 int main()
    18 {
    19     cin>>n;
    20     for(int i=1;i<=n;i++)
    21     {
    22         cin>>gua[i].a>>gua[i].b;
    23     }
    24     sort(gua+1,gua+1+n,cmp);
    25     memset(dp,-0x3f,sizeof(dp));
    26     dp[0][1]=0;
    27     for(int i=1;i<=n;i++)
    28     {
    29         for(int j=0;j<=n;j++)
    30         {
    31             dp[i][j]=max(dp[i-1][j],dp[i-1][max(j-gua[i].a,0)+1]+gua[i].b);
    32         }
    33     }
    34     int ans=-999999999;
    35     for(int i=0;i<=n;i++)
    36     {
    37         ans=max(ans,dp[n][i]);
    38     }
    39     cout<<ans<<endl;
    40     return 0;
    41 }
  • 相关阅读:
    python之元组
    python之dict
    python之list
    python之str字符串
    python之for循环
    Python的基本语法2
    Python的基本语法1
    初识python
    JS获取当天是周几
    EXCLE导入数据库
  • 原文地址:https://www.cnblogs.com/2529102757ab/p/11224793.html
Copyright © 2011-2022 走看看