欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

POJ1793&&EOJ21 Software Company

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


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

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

【本文對您有幫助就好】

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

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 久久综合丝袜日本网 | 天天综合久久 | 天天操天天干天天操 | 91精品国产一区二区三区 | 天堂中文在线最新版地址 | 成人无码T髙潮喷水A片小说 | 国产精品成人第一区 | 毛片a片免费看 | 99热在线免费观看 | 日韩在线观看视频网站 | 国产一区二区三区免费 | 欧美日批视频 | 999精品视频在线观看 | 国产激情网站 | 国产精品成人亚洲一区二区 | 日日摸夜夜添夜夜添亚洲女人 | 不卡在线一区 | 免费无遮挡很爽很污很黄 | 精品在线不卡 | 日韩电影在线看 | 99久久精品免费观看国产 | 一级黄色绿像片 | 三级高清| 日韩在线免费视频 | 欧美日韩国产综合一区二区三区 | 国产精品亚洲第一区二区三区 | 久久久婷 | 午夜影院在线观看 | 亚洲午夜在线 | 久久9999久久 | 国产精品久久久久久久久免费 | 久久国产精品久久 | 日韩精品a在线视频 | 欧美日韩中文字幕在线视频 | aaa欧美 | 欧美一区二区三区久久 | 久久久久成人网 | 中国一级特黄毛片大片 | 99久久免费国产精品 | 婷婷丁香色综合图亚洲 | 国产精品午夜小视频观看 |