zoukankan      html  css  js  c++  java
  • Nico Nico Ni~(完全背包)

    Time Limit:2000MS  Memory Limit:65535K

    Type: Program   Language: Not Limited

    Description

    Lys plays Love Live game now. You can level up via playing songs and get experiences ei but consume 
    spirit si.  Initially, you have n songs and spirit SP, empty experience. When you get enough experience, 
    you step in next level, and the experience you got flush to empty and the spirit will be filled full. 
    What’s more, when you step in next level, the total spirit SP will increase c, means you have c extra 
    spirit to consume, and required q more experiences to step in next level. 
    Now give you n songs, and the experience you can get and the spirit you should consume of each song. 
    The initially spirit SP you have, the first level experience requirement.  You can tell how the level 
    you can step in?
    

    Input

    First line has one integer t, the number cases.
    For each case, first line, n(1<=n<=10), n songs,  SP(1<=SP<=1000), the initial spirit, EP(1<=EP<=100000), 
    the first level requirement experiences,  
    c(1<=c<=100), the extra spirit you can get for each level,
    q(1<=q<=100), the extra requirement experiences for each level.
    Next n lines, for each line, has two integers, s, e,  consume spirit s and get experiences e for 
    each song.
    

    Output

    For each case, print the most level you can get. If the level is larger than 10000, you should only 
    output 10000.

    Sample Input

    1
    2  10  10  5  6
    3  3
    4  4
    

    Sample Output

    2

    Hint

    Before playing the song, you have 10 spirit, and require 10 experience to step into next level.
    You can play the first song two times and the second song one time, consume 10 spirt, and get 10 
    experiences, step level 2. And spirt become 15, and require 16 experiences to next level. Then 
    you can not step into next level with this spirit.
    

    思路:完全背包,每一次在背包容量为sp时,获得的最大价值为mv,当mv大于等于ep时,表示能升级,此时背包容量扩充为 sp + c, 升级条件变为 mv >= (ep + q)
    而随着背包容量的扩充,之前的dp[]已经保存了对应状态的最优值,故不必重新dp一遍
     1 /*
     2     times 108ms
     3     by orc
     4 */
     5 #include <cstdio>
     6 #include <iostream>
     7 #include <cstring>
     8 #include <algorithm>
     9 #include <queue>
    10 #include <set>
    11 using namespace std ;
    12 int n, sp, ep, c, q ;
    13 int s[15], e[15] ;
    14 int nsize ;
    15 int dp[1100000] ;
    16 int getans(int cur)
    17 {
    18     int& res = dp[cur] ;
    19     if(res != -1) return res ;
    20     res = 0 ;
    21     for(int i = 1; i <= n; ++i)
    22         if(cur >= s[i])
    23         res = max(res,getans(cur - s[i]) + e[i]) ;
    24     return res ;
    25 }
    26 int main()
    27 {
    28     #ifdef LOCAL
    29     freopen("in.txt","r",stdin) ;
    30     #endif
    31 
    32     int t ;
    33     scanf("%d",&t) ;
    34     while(t--)
    35     {
    36         scanf("%d%d%d%d%d",&n,&sp,&ep,&c,&q) ;
    37         for(int i = 1 ; i <= n; ++i) scanf("%d%d",&s[i],&e[i]) ;
    38         int nsize = sp, lev = 1;
    39              memset(dp, -1 ,sizeof dp) ;
    40               while(1)
    41               {
    42                   int now = getans(nsize) ;
    43                 //  printf("[%d]
    ",now) ;
    44                   if(now >= ep) {lev++; nsize += c ; ep += q ;}
    45 
    46                   else break ;
    47                   if(lev >= 10000) break ;
    48               }
    49               if(lev >= 10000) printf("10000
    ") ;
    50               else printf("%d
    ",lev) ;
    51     }
    52 
    53 }
    View Code
  • 相关阅读:
    mvc4 to mvc5 orEF5 to EF6 ,(升级EF6)
    mongodb 增删改查
    切换frame
    selenium使用,xpath解析模块,笔记整理在最后# 四套解析数据的方式 # 1.bs4 2.css_selector 3.xpath 4.re,
    爬虫,request,response 属性,方法,2.beautifulsoup解析模块
    爬虫基础知识简单案例
    vue跳转,v-model 双向绑定,-vuex的使用cookie:,视频第三方播放
    分页器,解析器,url控制器,响应器
    正向代理与反向代理
    认证权限频率自定义
  • 原文地址:https://www.cnblogs.com/orchidzjl/p/4518349.html
Copyright © 2011-2022 走看看