青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

USACO Section 3.1 Score Inflation

Score Inflation

The more points students score in our contests, the happier we here at the USACO are. We try to design our contests so that people can score as many points as possible, and would like your assistance.

We have several categories from which problems can be chosen, where a "category" is an unlimited set of contest problems which all require the same amount of time to solve and deserve the same number of points for a correct solution. Your task is write a program which tells the USACO staff how many problems from each category to include in a contest so as to maximize the total number of points in the chosen problems while keeping the total solution time within the length of the contest.

The input includes the length of the contest, M (1 <= M <= 10,000) (don't worry, you won't have to compete in the longer contests until training camp) and N, the number of problem categories, where 1 <= N <= 10,000.

Each of the subsequent N lines contains two integers describing a category: the first integer tells the number of points a problem from that category is worth (1 <= points <= 10000); the second tells the number of minutes a problem from that category takes to solve (1 <= minutes <= 10000).

Your program should determine the number of problems we should take from each category to make the highest-scoring contest solvable within the length of the contest. Remember, the number from any category can be any nonnegative integer (0, one, or many). Calculate the maximum number of possible points.

PROGRAM NAME: inflate

INPUT FORMAT

Line 1: M, N -- contest minutes and number of problem classes
Lines 2-N+1: Two integers: the points and minutes for each class

SAMPLE INPUT (file inflate.in)

300 4
100 60
250 120
120 100
35 20

OUTPUT FORMAT

A single line with the maximum number of points possible given the constraints.

SAMPLE OUTPUT (file inflate.out)

605

(Take two problems from #2 and three from #4.)

Analysis

This problem seems like a complete package problem, so do it traditionally with some amolaration. As the dynamic function can be writen as f[i][v]=max{f[i-1][v-k*t[i]]+s[i]|0<=k*t[i]<=M}, which aims to calculate the highest score after the choice of the ith problem class within v time. But we can calculate it in a new way.
Traditionally, we calculate it with some for loops:

for (int i=1;i<=N;i++)
    
for (int v=0;v<=M;v++){
        
for (int k=0;k*t[i]<=M;k++){
            
if (max<f[i-1][v-k*t[i]]+s[i]) max=f[i-1][v-k*t[i]]+s[i];
           }

           f[i][v]
=max;
       }
       

Sooner, this algorithm seems too slow for its three for loops and the cost of memories needs a lot. However, it's obvious to see the dynamic funtion is special because the ith situation can only be determined by the last situation: (i-1)th. So, records the result with a 1D array instead of the 2D one to  save memories.
Considering the fact that f[i][0]=0 is really useless, we can later change the 3 for loops into 2 loops and cut boundary. Here I provide the new algorithm:

for (int i=1;i<=N;i++)
    
for (int v=t[i];v<=M;v++)
        f[v]
=max{f[v],f[v-t[i]]+s[i]};

Code

/*
ID:braytay1
PROG:inflate
LANG:C++
*/

#include 
<iostream>
#include 
<fstream>
using namespace std;

int main(){
    ifstream fin(
"inflate.in");
    ofstream fout(
"inflate.out");
    
int N,M;
    fin
>>M>>N;
    
int f[10001];
    
int t[10001],s[10001];
    
for (int i=1;i<=N;i++){
        fin
>>s[i]>>t[i];
    }

    
for (int v=0;v<=M;v++){
        f[v]
=v/t[1]*s[1];
    }

    
for (int i=2;i<=N;i++){
        
int cost;
        cost
=t[i];
        
for (int v=cost;v<=M;v++){
            f[v]
=(f[v]>(f[v-t[i]]+s[i]))?f[v]:(f[v-t[i]]+s[i]);
        }

    }

    fout
<<f[M]<<endl;
    
return 0;
}

posted on 2008-08-20 17:14 幻浪天空領主 閱讀(366) 評論(0)  編輯 收藏 引用 所屬分類: USACO

<2025年12月>
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

導航

統計

常用鏈接

留言簿(1)

隨筆檔案(2)

文章分類(23)

文章檔案(22)

搜索

最新評論

閱讀排行榜

評論排行榜

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            亚洲夫妻自拍| 亚洲国产欧美一区| 亚洲欧美一区二区激情| 亚洲精品一二三| 欧美精品啪啪| 亚洲视频日本| 亚洲免费视频网站| 国产无一区二区| 免费高清在线一区| 欧美激情视频一区二区三区在线播放 | 亚洲伊人一本大道中文字幕| 国产精品素人视频| 久久一区二区视频| 欧美精品日本| 午夜精品视频网站| 久久久国产91| 99re66热这里只有精品3直播| 亚洲精品永久免费| 国产一区深夜福利| 亚洲国产婷婷香蕉久久久久久| 欧美精品久久久久久| 亚洲欧美在线一区二区| 久久久久网址| 亚洲校园激情| 久久久水蜜桃av免费网站| 在线亚洲欧美专区二区| 欧美一级在线视频| 一本一本久久a久久精品牛牛影视| 亚洲视频1区| 亚洲欧洲日本专区| 性欧美18~19sex高清播放| 亚洲激情av在线| 香蕉久久夜色精品国产使用方法| 亚洲高清资源综合久久精品| 中国成人在线视频| 亚洲精品国产欧美| 久久精品国产第一区二区三区| 在线视频你懂得一区| 久久精品99国产精品| 亚洲一区中文| 欧美激情一区二区三级高清视频| 欧美综合二区| 国产精品vvv| 亚洲激情电影在线| 在线观看欧美一区| 欧美一区二区三区视频| 亚洲一区二区高清| 欧美精品videossex性护士| 久久噜噜亚洲综合| 国产精品视频免费观看www| 亚洲人成精品久久久久| 永久久久久久| 久久不射2019中文字幕| 欧美一区二区三区日韩视频| 欧美精品二区| 亚洲国产精品久久久久秋霞影院| 精品999日本| 久久精品系列| 老司机精品福利视频| 国产亚洲欧美日韩日本| 午夜精品在线视频| 欧美影院一区| 国产欧美一区二区精品性 | 亚洲成在人线av| 伊人男人综合视频网| 性欧美在线看片a免费观看| 亚洲欧美日本国产专区一区| 欧美手机在线视频| 一区二区三区免费在线观看| 在线视频一区二区| 欧美三级电影大全| 亚洲视频精品| 欧美一区二区三区日韩| 国产精品一区二区在线观看| 亚洲欧美日韩成人| 久久九九国产精品怡红院| 国产一区二区三区四区| 久久激情中文| 欧美国产日韩视频| 999在线观看精品免费不卡网站| 欧美精品综合| 中日韩美女免费视频网站在线观看| 亚洲欧美日韩在线观看a三区| 国产女人精品视频| 久久久五月天| 亚洲人成网站影音先锋播放| 亚洲一区二区黄| 国产亚洲福利一区| 农村妇女精品| 亚洲视频播放| 美女被久久久| 亚洲社区在线观看| 国产尤物精品| 欧美精品久久久久久久久老牛影院 | 亚洲欧美网站| 在线观看亚洲精品视频| 欧美极品一区二区三区| 午夜精品久久久久久久久久久久久 | 国产精品都在这里| 久久精品亚洲乱码伦伦中文| 亚洲国产欧美国产综合一区| 亚洲在线中文字幕| 曰本成人黄色| 国产精品美女久久久久aⅴ国产馆| 久久久91精品| 亚洲午夜未删减在线观看| 久久亚洲风情| 亚洲欧美电影在线观看| 亚洲二区在线观看| 国产精品视频内| 欧美激情四色| 久久久青草婷婷精品综合日韩 | 亚洲精选久久| 美女主播精品视频一二三四| 中文亚洲欧美| 亚洲日韩第九十九页| 国产欧美在线观看| 欧美日韩亚洲一区二区三区四区| 久久精品国产久精国产爱| 一本色道久久加勒比精品| 欧美成人第一页| 久久精品国产第一区二区三区| 日韩亚洲精品电影| 亚洲高清电影| 国产一区二区三区免费在线观看| 欧美日韩另类综合| 欧美搞黄网站| 美女脱光内衣内裤视频久久网站| 午夜亚洲精品| 亚洲欧美日韩区| 亚洲午夜激情免费视频| 亚洲精品视频中文字幕| 欧美.www| 欧美jizz19hd性欧美| 久久久久一区二区| 欧美一区二区三区播放老司机 | 99视频有精品| 亚洲精品九九| 亚洲日本aⅴ片在线观看香蕉| 激情视频一区二区三区| 国产一区二区日韩精品| 国产欧美在线播放| 国产亚洲成年网址在线观看| 国产精品久久久久久亚洲调教| 欧美全黄视频| 欧美日韩喷水| 国产精品视频男人的天堂| 国产精品乱子久久久久| 国产精品三区www17con| 国产毛片一区| 国产一区二区三区丝袜| 韩日精品中文字幕| 黄色成人av网站| 亚洲国产精品一区二区第四页av | 一本色道久久综合一区| 亚洲美女诱惑| 亚洲尤物影院| 久久久久国产成人精品亚洲午夜| 久久久99精品免费观看不卡| 久久久久国产一区二区三区四区| 久久久久久噜噜噜久久久精品| 久久香蕉国产线看观看av| 蜜臀久久久99精品久久久久久 | 亚洲欧洲日本一区二区三区| 亚洲韩国精品一区| 99视频精品全国免费| 亚洲综合导航| 久久精品日产第一区二区| 免费h精品视频在线播放| 欧美理论在线播放| 国产伦理一区| 亚洲第一天堂av| 在线综合欧美| 久久免费午夜影院| 亚洲国产日韩精品| 亚洲一区二区视频在线观看| 欧美亚洲尤物久久| 欧美精品xxxxbbbb| 国产精品亚洲一区| 亚洲国产乱码最新视频| 亚洲一区二区成人| 久热精品视频在线免费观看| 91久久在线视频| 久久爱www.| 欧美午夜激情视频| 亚洲国产欧美在线人成| 亚洲一区二区三区中文字幕在线 | 男人的天堂亚洲| 一本色道久久综合| 久久免费黄色| 国产精品免费看片| 亚洲高清视频一区| 性欧美长视频| 亚洲精品一区二区三| 久久久蜜桃精品| 国产精品家庭影院| 日韩午夜在线观看视频| 美女免费视频一区| 午夜影院日韩| 国产精品久久网站|