Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
大牛帮忙看一下,TLE~~~#include <stdio.h> #include <algorithm> #include <memory.h> #include <string.h> #include <vector> using namespace std; const int MAX_N = 101; const int MAX_M = 100001; int f[MAX_M]; void Solve (int a[], int c[], int n, int m) { int i = 0; int k = 0; int v[MAX_M] = {0}; memset(f, 0, sizeof(f)); f[0] = 1; int count = 0; for (i = 0; i < n; ++i) { memset(v, 0, sizeof(v)); for (k = 0; k <= m - a[i]; ++k) { if (f[k] != 0 && f[k+a[i]] == 0 && v[k] < c[i]) { f[k+a[i]] = 1; v[k+a[i]] = v[k] + 1; ++count; } } } printf ("%d\n", count); } int main() { //freopen ("D:/VC Project/Test/Test/Data.txt", "r", stdin); //Solve (); int n = 0; int m = 0; int a[MAX_N] = {0}; int c[MAX_N] = {0}; while (true) { scanf ("%d%d", &n, &m); if (n == 0 && m == 0) { break; } int i = 0; for (i = 0; i < n; ++i) { scanf ("%d", a+i); } for (i = 0; i < n; ++i) { scanf ("%d", c+i); } //Solve (a, c, n, m); int k = 0; int v[MAX_M] = {0}; memset(f, 0, sizeof(f)); f[0] = 1; int count = 0; for (i = 0; i < n; ++i) { memset(v, 0, sizeof(v)); for (k = 0; k <= m - a[i]; ++k) { if (f[k] != 0 && f[k+a[i]] == 0 && v[k] < c[i]) { f[k+a[i]] = 1; v[k+a[i]] = v[k] + 1; ++count; } } } printf ("%d\n", count); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator