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

O(10*100000)的方法是不是巨弱啊

Posted by EVILsupermp5 at 2013-12-02 15:33:24 on Problem 1276
小弟没好好学过背包只想出这个 C++ 32ms AC

#include <cstdio>
int main()
{
    int C, N, a[11], w[11], i, j, k, p;
    while (scanf("%d", &C) != EOF)
    {
        int f[100001] = {0};
        f[0] = 1;
        scanf("%d", &N);
        for (i = 1; i <= N; i++)
        {
            scanf("%d%d", &a[i], &w[i]);
            for (k = 100000; k; k--)
                if (k - w[i] >= 0 && f[k - w[i]])
                    for (p = k, j = 0; j < a[i]; j++)
                    {
                        if (p > 100000 || f[p] == i) break;
                        f[p] = i;
                        p += w[i];
                    }
        }
        for (i = C; !f[i]; i--);
        printf("%d\n", i);
    }
}

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