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 |
这题真的不是贪心?#include <stdio.h> #include <string.h> int main(int argc, char * argv[]) { int weight[100]; int count [100]; int capacity, size; int available[100001]; int direction[100001]; int distance [100001]; int answer; int i, j; for ( ; ; ) { scanf("%d%d", &size, &capacity); if ( ( capacity == 0 ) && ( size == 0 ) ) { break; } for ( i = 0; i < size; ++i ) { scanf("%d", &weight[i]); } for ( i = 0; i < size; ++i ) { scanf("%d", &count[i]); } answer = 0; memset(available, 0, sizeof(available)); memset(direction, 0, sizeof(direction)); memset(distance, 0, sizeof(distance )); available[0] = 1; for ( i = 0; i < size; ++i ) { for ( j = weight[i]; j <= capacity; ++j ) { if ( available[j] == 1 ) { continue; } if ( available[ j - weight[i] ] == 0 ) { continue; } if ( ( direction[ j - weight[i] ] == ( i + 1 ) ) && ( distance[ j - weight[i] ] == count[i] ) ) { continue; } available[j] = 1; direction[j] = ( i + 1 ); distance [j] = ( direction[ j - weight[i] ] == ( i + 1 ) ? distance[ j - weight[i] ] + 1 : 1 ); answer++; } } printf("%d\n", answer); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator