BNU 28890 &zoj 3689--digging —————— "01 Backpack for order of items"

Source: Internet
Author: User

Diggingtime limit:2000msmemory limit:65536kbthis problem'll be judged onZju. Original id:3689
64-bit integer IO format: %lld Java class name: Main Prev Submit Status Statistics discuss Next

When it comes Maya Civilization to the, we can quickly remind of a term called the end of the world. It's not difficult-understand why we choose to believe the prophecy (or we just assume it's true to entertain Ourselve s) If you know the other prophecies appeared in the Maya Calendar . For instance, it had accurately predicted a solar eclipse on July 22, 2009.

The ancient civilization, such as  old Babylonianhas ,   ancient Egypt  and etc, Some features in common. One of them is the tomb because of the influence of the religion. At this time, the symbol of the tomb is the pyramid. Many of these structures featured a top platform upon which a smaller dedicatory building was constructed, associated with a particular  Maya deity . Maya Pyramid-like structures were also erected to serve as a place of interment for powerful rulers.

Now there are , N  coffin Chambers in the pyramid waiting for building and the ruler have recruited so Me workers to work for  T  days. It takes  ti days to complete the  ith  coffin chamber. the size of the  ith  coffin chamber is  si . They use a very special method to calculate the reward for workers. If starting to build the , ith  coffin chamber when there are  T  days  left , they can get  t*si  units of gold. If they has finished a coffin chamber, then they can choose another coffin chamber to build (if they decide to build the& nbsp ith  coffin chamber at the time  T , then they can decide next coffin chamber at the Time&nbs P t-ti ).

At the beginning, there is days left T . If They start the last work t t-ti < 0 at the time and the finishing time, they won't get the last pay.

Input

There is few test cases.

The first line contains N , T (1≤ N ≤3000,1≤ T ≤10000), indicating there is N coffin chambers to B E built, and there is days for T workers working. Next N lines contains ti , si (1≤ ti , si ≤500).

All numbers is integers and the answer would not exceed 2^31-1.

Output

For each test case, output an integer in a single line indicating the maxminal units of gold the workers would get.

Sample Input
3 103 41) 22 1
Sample Output
62
Hint

Start the second task at the time 10
Start the first task at the time 9
Start the third task at the time 6
The answer is 10*2+9*4+6*1=62

Title: give you n items, T-day. Each item is ti,si again. Said Ti days to build, and the reward is si*t. T is the time when the item was started. Problem-solving ideas: When the game with 01 Backpack wrote, but has not been pushed out of the sample. After the game, it is necessary to see what others say is the order in which the items are placed in the backpack. Should choose cost-effective from low to high order to go DP. The advantage is that for cost-effective items, will not be cost-effective coverage, the higher the cost, the more likely to be retained. Thus ensuring greater value for the acquisition.
/* Update the status in the order of price ratio from low to high, so that the cost-effective coffin will inevitably appear at the T-big time, which will be arranged first. If cost-effective in front of the DP update, may be cost-effective will be overwritten, resulting in the loss of the optimal solution. */#include <bits/stdc++.h>using namespace Std;const int maxv=1e4+100;int dp[maxv];struct coffin{    int t,s;} Goods[3200];int M;bool cmp (Coffin A,coffin b) {    return a.s*1.0/a.t<b.s*1.0/b.t;} void Zeroonepack (Coffin x) {    int i;    for (i=m;i>=x.t;i--) {        Dp[i]=max (DP[I],DP[I-X.T]+I*X.S);    }} int main () {    int n,i,j,res;    while (scanf ("%d%d", &n,&m)!=eof) {        memset (dp,0,sizeof (DP));        for (i=0;i<n;i++) {            scanf ("%d%d", &GOODS[I].T,&GOODS[I].S);        }        Sort (goods,goods+n,cmp);        for (i=0;i<n;i++) {            zeroonepack (goods[i]);        }        res=0;        for (i=0;i<=m;i++) {            Res=max (res,dp[i]);        }        printf ("%d\n", res);    }    return 0;}

  

BNU 28890 &zoj 3689--digging —————— "01 Backpack for order of items"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.