亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

POJ1793&&EOJ21 Software Company

系統(tǒng) 1965 0
POJ1793&&EOJ21 Software Company
Time Limit: ?1000MS ? Memory Limit: ?30000K
Total Submissions: ?864 ? Accepted: ?348

Description

A software developing company has been assigned two programming projects. As both projects are within the same contract, both must be handed in at the same time. It does not help if one is finished earlier.?

This company has n employees to do the jobs. To manage the two projects more easily, each is divided into m independent subprojects. Only one employee can work on a single subproject at one time, but it is possible for two employees to work on different subprojects of the same project simultaneously.?

Our goal is to finish the projects as soon as possible.?

Input

The first line of the input file contains a single integer t (1 <= t <= 11), the number of test cases, followed by the input data for each test case. The first line of each test case contains two integers n (1 <= n <= 100), and m (1 <= m <= 100). The input for this test case will be followed by n lines. Each line contains two integers which specify how much time in seconds it will take for the specified employee to complete one subproject of each project. So if the line contains x and y, it means that it takes the employee x seconds to complete a subproject from the first project, and y seconds to complete a subproject from the second project.

Output

There should be one line per test case containing the minimum amount of time in seconds after which both projects can be completed.

Sample Input

    
      1

3 20

1 1

2 4

1 6


    
  

Sample Output

    
      18
    
  
    
      *********************************************************
    
  
    
      題目大意:一個公司要生產(chǎn)兩種軟件,現(xiàn)在每種軟件有m個。有n個員工,第i個員工做一個軟件a要a[i]的時間,做一個軟件b要b[i]的時間,問做完全部的軟件最少需要的時間。
    
  
    
      解題思路:二分答案+dp背包;
    
  
    
      網(wǎng)上都這么說。表示dp我學藝不精,一開始還真沒想到該dp,當看到別人說這道題是dp的時候,心拔涼拔涼的,自以為對dp還算比較了解的我= =沒想出來該怎么dp。這道題有幾個糾結的地方:1.人員怎么分配;2.要dp的話,dp的狀態(tài)是什么,下小標是什么,dp數(shù)組保存的是什么,根據(jù)什么dp;3.感覺變量好多還是相互聯(lián)系的。
    
  
    
      沒辦法,參考了網(wǎng)上的眾多結題報告才明白是怎么回事。dp[i][j]表示在tim的時間內(nèi)前i個員工做了a軟件j個之后所能做的b軟件的最大值,dp里面的是b軟件的最大值,那個tim是二分時間得來的??梢韵氲猛ǎ寒攖im增加的時候,dp[i][j]一定是不減的,所以可以二分時間。當dp[n][m]>=m也就是n個員工在tim的時間內(nèi)做了m個a軟件以及超過m的b軟件,所以,假定的時間tim就可以縮小。至于dp[i][j]的狀態(tài)轉(zhuǎn)移:
    
  
    
      dp[i][j]=max{dp[i][j],dp[i-1][j-k]+(tim-k*a[i])/b[i]};這個方程也是網(wǎng)上共有的。(tim-k*a[i])/b[i]表示分配給第i個員工k件a軟件然后在tim時間內(nèi)做完的b軟件的個數(shù)。這個狀態(tài)轉(zhuǎn)移,說實話,一開始沒想通,的確很妙。
    
  
    
      二分答案,把時間這個變量固定下來,dp第一維,把員工變量固定下來,dp第二維,把a軟件的制作個數(shù)固定下來,dp的內(nèi)容,來驗證二分答案的正確性。完美啊。
    
  
      #include <stdio.h>

#include <string.h>

#include <vector>

#define N 105

#define INF 0x3f3f3f3f

using namespace std;



int n,m,maxx;

int a[N],b[N];

int dp[N][N];



int ok(int tim)

{

    memset(dp,-1,sizeof(dp));

    for(int i=0;i<=m;i++)

        if(i*a[1]<=tim)

            dp[1][i]=(tim-i*a[1])/b[1];

        else break;

    for(int i=2;i<=n;i++)

    {

        for(int j=0;j<=m;j++)

            for(int k=0;k<=j&&a[i]*k<=tim;k++)

                if(dp[i-1][j-k]!=-1)

                    dp[i][j]=max(dp[i][j],dp[i-1][j-k]+(tim-k*a[i])/b[i]);

    }

    return  dp[n][m]>=m;

}



void re(void)

{

    maxx=0;

    scanf("%d%d",&n,&m);

    for(int i=1;i<=n;i++)

    {

        scanf("%d%d",&a[i],&b[i]);

        maxx=max(a[i],maxx);

        maxx=max(b[i],maxx);

    }

}



void run(void)

{

    int le=0,ri=maxx*m*2,mid;

    while(mid=(le+ri)/2,le<ri)

    {

        if(ok(mid))ri=mid;

        else           le=mid+1;

    }

    printf("%d\n",ri);

}



int main()

{

    int ncase;

    scanf("%d",&ncase);

    while(ncase--)

    {

        re();

        run();

    }

    return 0;

}


    

    
      

POJ1793&&EOJ21 Software Company


更多文章、技術交流、商務合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦?。?!

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 精品四虎免费观看国产高清午夜 | 欧美一级艳片视频免费观看 | 国产操片 | 久久精品免费全国观看国产 | 国产成人综合欧美精品久久 | 成人亚洲国产精品久久 | 欧美伊香蕉久久综合类网站 | 91精品国产9l久久久久 | 男人天堂日韩 | 五月天亚洲婷婷 | 九九精品国产 | 天天鲁天天爱天天鲁天天 | 中文字幕国产专区 | 玖玖精品在线视频 | 国产精品第二页在线播放 | 国产日韩欧美精品一区二区三区 | 亚洲精品福利视频 | 国产a网| 四虎永久精品免费网址大全 | 久热这里只精品热在线观看 | 免费国产免费福利视频 | 巴西一级毛片 | 一级特黄性色生活片 | xxxxxx国产精品视频 | 久久免费精品视频在线观看 | 九九热视频免费 | 婷婷色香五月激情综合2020 | 九九热最新 | 久久亚洲国产中v天仙www | 欧美日韩在大午夜爽爽影院 | 久久国产高清字幕中文 | 日韩女人毛片在线播放 | 日韩一区二区免费看 | 国产精品天堂 | 亚洲福利 影院 | 91亚洲精品福利在线播放 | 91精品国产91热久久p | 欧美中文字幕视频 | 成人免费视频在 | 91视频看 | 色噜噜亚洲精品中文字幕 |