首页 > ACM题库 > 九度OJ > 九度-1123-采药[解题代码]
2013
12-12

九度-1123-采药[解题代码]

题目来源:2008年北京大学图形实验室计算机研究生机试真题

题目描述:

辰辰是个很有潜能、天资聪颖的孩子,他的梦想是称为世界上最伟大的医师。
为此,他想拜附近最有威望的医师为师。医师为了判断他的资质,给他出了一个难题。
医师把他带到个到处都是草药的山洞里对他说:
“孩子,这个山洞里有一些不同的草药,采每一株都需要一些时间,每一株也有它自身的价值。
我会给你一段时间,在这段时间里,你可以采到一些草药。如果你是一个聪明的孩子,你应该可以让采到的草药的总价值最大。”
如果你是辰辰,你能完成这个任务吗?

输入:

输入的第一行有两个整数T(1 <= T <= 1000)和M(1 <= M <= 100),T代表总共能够用来采药的时间,M代表山洞里的草药的数目。
接下来的M行每行包括两个在1到100之间(包括1和100)的的整数,分别表示采摘某株草药的时间和这株草药的价值。

输出:

可能有多组测试数据,对于每组数据,
输出只包括一行,这一行只包含一个整数,表示在规定的时间内,可以采到的草药的最大总价值。

样例输入:
70 3
71 100
69 1
1 2
样例输出:
3

cpp 代码如下:
#include <iostream>
using namespace std;

int t[10001];
int T,M;

int main(){
    int a,b;
    while(cin>>T>>M){
        for(int j=0;j<=T;j++){
            t[j] = 0;
        }
        for(int i=0;i<M;i++){
            cin>>a>>b;
            for(int j=T;j>=a;j--){
                int v = t[j-a] + b;
                if(v>t[j]){
                    t[j] = v;
                }
            }
        }
        int max = 0;
        for(int i=0;i<=T;i++){
            //cout<<t[i]<<" ";
            if(t[i]>max){
                max = t[i];
            }
        }
        cout<<max<<endl;
    }
    return 0;
}
/**************************************************************
	Problem: 1123
	User: coder
	Language: C++
	Result: Accepted
	Time:120 ms
	Memory:1556 kb
****************************************************************/


  1. Hello Web Admin, I noticed that your On-Page SEO is is missing a few factors, for one you do not use all three H tags in your post, also I notice that you are not using bold or italics properly in your SEO optimization. On-Page SEO means more now than ever since the new Google update: Panda. No longer are backlinks and simply pinging or sending out a RSS feed the key to getting Google PageRank or Alexa Rankings, You now NEED On-Page SEO. So what is good On-Page SEO?First your keyword must appear in the title.Then it must appear in the URL.You have to optimize your keyword and make sure that it has a nice keyword density of 3-5% in your article with relevant LSI (Latent Semantic Indexing). Then you should spread all H1,H2,H3 tags in your article.Your Keyword should appear in your first paragraph and in the last sentence of the page. You should have relevant usage of Bold and italics of your keyword.There should be one internal link to a page on your blog and you should have one image with an alt tag that has your keyword….wait there's even more Now what if i told you there was a simple WordPress plugin that does all the On-Page SEO, and automatically for you? That's right AUTOMATICALLY, just watch this 4minute video for more information at.