Luo Gu 1800 software

  1. The meaning of problems: a company to develop two software modules each having m, there are n technical staff, each person different software development time.
  2. Thinking: are seeking maximum minimum problems, the maximum for the minimum number of days to complete two tasks. And the answer is monotonic, I think of binary answer is obtained for a few days, it is necessary to determine whether feasible, then think of DP (Kind backpack). The current number of days to do the m 1 m do software meets the software basis for judging 2.
  3. Meaning equation: f [i] [j] represents the individual before i can do to make the most of several software modules j II software module 1.

    4. equation: f [i] [j] = max {f [i] [j], f [i-1] [k] + res / b [i]} // See code comments

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdlib>
using namespace std;
const int N=110;
int n,m,a[N],b[N],l,r,mid,ans;
int f[N][N];

 bool dp(int num)
{
    memset(f,0,sizeof(f));
    f[0][0]=1;//初始化
    int i,j,k,res;
    for (i=1; i<=n; i++)
        for (j=0; j<=m; j++)
            for (k=j; k>=0; k--)//i-1个人做k个软件1模块,第i个人做j-k个
            {
                res=num-a[i]*(j-k);
                if (res<0) break;//判断第i个人能否做
                if (f[i-1][k]>0) f[i][j]=max(f[i][j],f[i-1][k]+res/b[i]);
            }
    
    if (f[n][m]>m) return true;
    return false;
}
 int main()
{
    int tmp=0;
    scanf("%d%d",&n,&m);
    for (int i=1; i<=n; i++) 
    {
        scanf("%d%d",&a[i],&b[i]);
        if (a[i]+b[i]>tmp) tmp=a[i]+b[i];
    }
    r=tmp*m; l=1;
    while (l<=r)
    {
        mid=(l+r)/2;
        if (dp(mid)) {ans=mid; r=mid-1;}
        else l=mid+1;
    }//熟悉的二分
    printf("%d\n",ans);
    return 0;
}

Guess you like

Origin www.cnblogs.com/lyxzhz/p/12388569.html