zoukankan      html  css  js  c++  java
  • P1060-开心的金明

     1 #include <bits/stdc++.h>
     2 #define _for(i,a,b) for(int i = (a);i < b;i ++)
     3 typedef long long ll;
     4 using namespace std;
     5 int N,m;
     6 inline ll read()
     7 {
     8     ll ans = 0;
     9     char ch = getchar(), last = ' ';
    10     while(!isdigit(ch)) last = ch, ch = getchar();
    11     while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
    12     if(last == '-') ans = -ans;
    13     return ans;
    14 }
    15 inline void write(ll x)
    16 {
    17     if(x < 0) x = -x, putchar('-');
    18     if(x >= 10) write(x / 10);
    19     putchar(x % 10 + '0');
    20 }
    21 int dp[26][30009];
    22 int a[2][30];
    23 int main()
    24 {
    25     N = read(),m = read();
    26     _for(i,1,m+1)
    27         _for(j,0,2)
    28             a[j][i] = read(); 
    29     memset(dp,0,sizeof(dp));
    30     _for(i,1,m+1)
    31     {
    32         _for(j,0,N+1)
    33         {
    34             if(a[0][i] <= j)
    35                 dp[i][j] = max(dp[i-1][j],dp[i-1][j-a[0][i]]+a[0][i]*a[1][i]);
    36             else
    37                 dp[i][j] = dp[i-1][j];
    38         }
    39     }
    40     write(dp[m][N]);
    41     return 0;
    42 }
  • 相关阅读:
    TreeMap
    索引
    B-树、B+树
    硬盘速度、存储方式
    2-3树
    多叉树、2-3-4树
    红黑树
    平衡树、AVL树
    树、多路树、二叉树
    Java实现后缀表达式建立表达式树
  • 原文地址:https://www.cnblogs.com/Asurudo/p/11298138.html
Copyright © 2011-2022 走看看