zoukankan      html  css  js  c++  java
  • D

    Description

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

    The ancient civilization, such as Old BabylonianhasAncient Egypt and etc, some features in common. One of them is the tomb because of the influence of the religion. At that 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 has recruited some workers to work for T days. It takesti 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 have finished a coffin chamber, then they can choose another coffin chamber to build (if they decide to build the ith coffin chamber at the time t, then they can decide next coffin chamber at the time t-ti).

    At the beginning, there are T days left. If they start the last work at the time t and the finishing time t-ti < 0, they will not get the last pay.

    Input

    There are few test cases.

    The first line contains NT (1 ≤ N ≤ 3000,1 ≤ T ≤ 10000), indicating there are N coffin chambers to be built, and there are T days for workers working. Next N lines contains tisi (1 ≤ tisi ≤ 500).

    All numbers are integers and the answer will 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 will get.

    Sample Input

    3 10
    3 4
    1 2
    2 1
    

    Sample Output

    62
    **********************************************************************************************************************************************************************************************************************************************************************************************************************
     1 /*
     2 有公式 a.s*t+(t-a.t)*b.s  和
     3   b.s*t+(t-b.t)*a.s
     4   两者之差  a.s*b.t-b.s*a,t
     5   即单位密度,可据此作为排序条件判断排序
     6   其实到最后得出的就是一个01背包问题
     7  */
     8 #include<iostream>
     9 #include<string>
    10 #include<cstring>
    11 #include<cmath>
    12 #include<cstdio>
    13 #include<algorithm>
    14 using namespace std;
    15 struct coffin
    16 {
    17     int s,t;
    18 }c[3001];
    19 int n,t,dp[100001];
    20 bool cmp(const coffin &a,const coffin &b)
    21 {
    22     return a.s*b.t<a.t*b.s;
    23 }
    24 int main()
    25 {
    26     int i,j,k;
    27     while(scanf("%d %d",&n,&t)!=EOF)
    28     {
    29         for(i=0;i<n;i++)
    30          scanf("%d %d",&c[i].t,&c[i].s);
    31         sort(c,c+n,cmp);
    32         memset(dp,0,sizeof(dp));
    33         for(i=0;i<n;i++)
    34         {
    35             for(j=t;j-c[i].t>=0;j--)
    36               if(dp[j]<dp[j-c[i].t]+j*c[i].s)
    37                  dp[j]=dp[j-c[i].t]+j*c[i].s;
    38         }
    39         printf("%d
    ",dp[t]);
    40     }
    41     return 0;
    42 }
    View Code
  • 相关阅读:
    perl练习——FASTA格式文件中序列GC含量计算&perl数组排序如何获得下标或者键
    短序列组装Sequence Assembly(转载)
    MEGA软件——系统发育树构建方法(图文讲解) 转载
    R语言中的read.table()
    网络七层模型OSI(Open System Interconnection)
    MySQL报错“The server time zone value '�й���׼ʱ��' is unrecognized”
    JDK环境变量配置
    netstat命令
    敏捷方法论(Agile Methodologies)
    0 upgraded, 0 newly installed, 0 to remove and 6 not upgraded解决方法
  • 原文地址:https://www.cnblogs.com/sdau--codeants/p/3445928.html
Copyright © 2011-2022 走看看