zoukankan      html  css  js  c++  java
  • http://47.95.147.191/contest/4/problem/A

    http://47.95.147.191/contest/4/problem/A
    f[i][j]表示已经完成j道且最后一个月完成[i,j]题目的最少月数。

    #include <iostream>
    #include <cstdio>
    #include <queue>
    #include <algorithm>
    #include <cmath>
    #include <cstring>
    #define inf 2147483647
    #define N 1000010
    #define p(a) putchar(a)
    #define For(i,a,b) for(long long i=a;i<=b;++i)
    
    using namespace std;
    long long n,k,ans;
    long long f[1010][1010],sum1[1010],sum2[1010];//已经完成i-1道,最后一个月完成[i,j]道的最小天数
    struct node{
        long long x;
        long long y;
    }a[N];
    void in(long long &x){
        long long y=1;char c=getchar();x=0;
        while(c<'0'||c>'9'){if(c=='-')y=-1;c=getchar();}
        while(c<='9'&&c>='0'){ x=(x<<1)+(x<<3)+c-'0';c=getchar();}
        x*=y;
    }
    void o(long long x){
        if(x<0){p('-');x=-x;}
        if(x>9)o(x/10);
        p(x%10+'0');
    }
    
    signed main(){
        in(k);in(n);
        For(i,1,n){
            in(a[i].x);in(a[i].y);
            sum1[i]=sum1[i-1]+a[i].x;
            sum2[i]=sum2[i-1]+a[i].y;
        }
        For(i,1,n)
            For(j,1,n)
                f[i][j]=inf;
        For(i,1,n) if(sum1[i]<=k&&sum2[i]<=k) f[1][i]=3;
        ans=inf;
        //[i,j]
        For(j,2,n)
            For(i,2,j)
                For(t,1,i-1){
                    if(sum1[j]-sum1[i-1]<=k&&sum2[j]-sum2[i-1]<=k) f[i][j]=min(f[i][j],f[t][i-1]+2);
                    if(sum1[j]-sum1[i-1]+sum2[i-1]-sum2[t-1]<=k&&sum2[j]-sum2[i-1]<=k) f[i][j]=min(f[i][j],f[t][i-1]+1);
                    if(j==n) ans=min(ans,f[i][j]);
                }
        o(ans);
        return 0;
    }
  • 相关阅读:
    JavaScript中Null和Undefined的区别
    javascript中的计算题
    数组去重
    javascript面向对象中继承实现的几种方式
    数列求值 题解
    首字母变大写 题解
    发工资咯:) 题解
    绝对值排序 题解
    数列有序 题解
    母牛的故事 题解
  • 原文地址:https://www.cnblogs.com/war1111/p/12364187.html
Copyright © 2011-2022 走看看