Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

70周年校庆当天的1A留念。无穷背包+多重背包(记录使用状态,非0-1拆解,非双端队列)见代码~

Posted by vjubge4 at 2019-06-16 16:38:50 on Problem 3260
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int oo = 0x3f3f3f3f;
int N, T;
int V[100], C[100];
int dp1[125 * 125];
int dp2[10005 + 125 * 125];
int used[10005 + 125 * 125];

int main(){
    scanf("%d %d", &N, &T);
    int max_val = -1;
    for(int i =0; i < N; i ++){
        scanf("%d", V + i);
        max_val = max(max_val, V[i]);
    }
    for(int i =0; i < N; i ++){
        scanf("%d", C + i);
    }
    memset(dp1, oo, sizeof(dp1));
    dp1[0] = 0;
    for(int i =0; i < N; i ++){
        for(int j = V[i]; j <= max_val * max_val; j ++){
            dp1[j] = min(dp1[j], dp1[j - V[i]] + 1);
        }
    }
    memset(dp2, oo, sizeof(dp2));
    dp2[0] = 0;
    for(int i = 0; i < N; i ++){
        memset(used, 0, sizeof(used));
        for(int j = V[i]; j <= T + max_val * max_val; j ++){
            if(used[j - V[i]] < C[i]){
                int t = dp2[j - V[i]] + 1;
                if(dp2[j] > t){
                    dp2[j] = t;
                    used[j] = used[j - V[i]] + 1;
                }
            }
        }
    }
    int res = oo;
    for(int i = T; i <= T + max_val * max_val; i ++){
        int t = dp2[i] + dp1[i - T];
        res = min(res, t);
    }
    if(res == oo){
        printf("-1");
    } else {
        printf("%d", res);
    }
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator