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

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>
            亚洲黄色毛片| 欧美mv日韩mv国产网站app| 亚洲电影免费在线| 久久成人免费日本黄色| 欧美激情第9页| 亚洲日本中文字幕| 亚洲第一精品福利| 巨乳诱惑日韩免费av| 在线观看亚洲视频| 免费国产一区二区| 久久天堂精品| 国产日本欧美一区二区三区| 亚洲尤物精选| 亚洲视频在线视频| 国产精品日韩在线播放| 亚洲精品女av网站| 亚洲人久久久| 国产精品www色诱视频| 亚洲一区二区在| 亚洲私人影吧| 国产欧美综合在线| 久久久一本精品99久久精品66| 久久国产精品一区二区| 在线国产精品一区| 亚洲人成高清| 欧美香蕉大胸在线视频观看| 香蕉精品999视频一区二区| 亚洲欧美卡通另类91av| 亚洲人成啪啪网站| 欧美成人一品| 欧美日本三区| 欧美一区二区三区视频在线| 午夜一区二区三区在线观看| 伊人一区二区三区久久精品| 亚洲二区在线观看| 国产精品一级二级三级| 欧美.com| 国产精品麻豆va在线播放| 性欧美1819sex性高清| 久久久久一区二区三区| 99国产精品国产精品毛片| 亚洲大片一区二区三区| 欧美日韩一区三区四区| 欧美综合国产精品久久丁香| 亚洲自拍三区| 亚洲美女视频| 亚洲女人av| 日韩一级黄色片| 亚洲一区在线观看视频| 亚洲国产精品一区| 亚洲一区二区三区免费在线观看 | 亚洲伦理在线观看| 欧美国产一区二区三区激情无套| 在线综合欧美| 欧美国产专区| 蜜臀久久久99精品久久久久久| 99热在这里有精品免费| 欧美一乱一性一交一视频| 亚洲精品一级| 久久免费午夜影院| 亚洲欧美成人一区二区在线电影| 麻豆视频一区二区| 久久精品国产欧美激情| 国产精品高潮呻吟| 亚洲国产一区二区三区在线播 | 91久久中文字幕| 亚洲视频免费在线| 亚洲免费av电影| 久久久亚洲国产美女国产盗摄| 中文一区字幕| 国产视频一区在线观看| 99这里只有久久精品视频| 在线播放中文一区| 久久国产免费看| 欧美伊久线香蕉线新在线| 欧美日韩视频在线| 亚洲精品久久久久久久久久久久久| 国产欧美在线播放| 亚洲一区综合| 亚洲自拍偷拍网址| 国产精品高清在线| 在线一区二区视频| 亚洲在线视频| 国产精品毛片va一区二区三区| 亚洲人成人一区二区三区| 91久久精品美女| 免费在线成人av| 亚洲成人在线视频播放 | 欧美承认网站| 在线观看一区二区精品视频| 久久国产黑丝| 蜜桃av一区二区| 在线欧美亚洲| 欧美成人一区二区在线| 亚洲国产另类久久久精品极度| 亚洲激情啪啪| 欧美日韩一区二区免费在线观看 | 99re6热只有精品免费观看| 欧美精品手机在线| 日韩一区二区高清| 日韩网站免费观看| 欧美体内谢she精2性欧美 | 亚洲理论在线| 欧美日韩国产成人| 亚洲一区二区三区高清 | 狠狠88综合久久久久综合网| 久久国产欧美精品| 亚洲国产一区二区三区a毛片| 99视频超级精品| 国产精品网站视频| 欧美中文在线观看国产| 欧美国产亚洲视频| 一区二区免费看| 国产精品一区二区黑丝| 久久欧美肥婆一二区| 亚洲黄色av一区| 久久国产66| 国产欧美大片| 美女啪啪无遮挡免费久久网站| 欧美高清视频| 亚洲最新在线| 欧美三级午夜理伦三级中视频| 99re在线精品| 久久综合给合久久狠狠狠97色69| 亚洲观看高清完整版在线观看| 欧美日韩三级电影在线| 久久久国产亚洲精品| 亚洲美女电影在线| 久久综合电影一区| 性做久久久久久久久| 91久久久亚洲精品| 国产一区二区三区自拍| 欧美日韩亚洲国产精品| 久久久人成影片一区二区三区| 久久影音先锋| 在线看国产一区| 国产精品尤物福利片在线观看| 免费在线观看成人av| 亚洲欧美一区二区三区久久| 亚洲国产成人91精品 | 久久久久久一区| 亚洲视频碰碰| 91久久精品国产91性色 | 国产麻豆日韩欧美久久| 久久久久国色av免费观看性色| 9久草视频在线视频精品| 欧美激情亚洲自拍| 久久免费国产精品| 欧美在线高清视频| 亚洲乱码国产乱码精品精98午夜 | 欧美成人免费全部| 久久国产精品免费一区| 亚洲欧美bt| 亚洲影院免费观看| 亚洲图片在区色| 日韩视频在线一区二区| 91久久极品少妇xxxxⅹ软件| 国产一区二区三区高清播放| 国产精品高潮呻吟| 国产精品久久久久久久7电影| 欧美日韩精品免费观看视频完整| 欧美成人精品在线视频| 久久综合狠狠综合久久综合88| 欧美一区二区三区四区夜夜大片| 亚洲欧美成人| 亚洲欧美综合一区| 久久99在线观看| 欧美一二三视频| 欧美在线观看日本一区| 久久久99久久精品女同性| 欧美一区免费视频| 久久嫩草精品久久久精品一| 久久视频一区二区| 久久综合色影院| 美女脱光内衣内裤视频久久网站| 麻豆久久精品| 欧美日韩1区2区| 牛人盗摄一区二区三区视频| 欧美国产三级| 欧美日韩在线三区| 国产精品一区久久| 国产一区二区三区的电影| 伊人婷婷久久| 亚洲欧美日韩国产一区| 欧美mv日韩mv国产网站app| 一区二区三区福利| 久久精选视频| 国产精品久久久久久久久久久久久久| 国产一区二区三区久久久久久久久| 91久久精品国产91久久性色tv | 亚洲国产精品一区二区第四页av| 亚洲一区二区精品在线| 久久综合婷婷| 亚洲天堂av高清| 欧美激情一区二区| 狠狠狠色丁香婷婷综合久久五月| 亚洲视频一区二区免费在线观看| 久久综合九色综合欧美就去吻| 亚洲一区二区三区激情| 欧美美女日韩|