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 |
用DP都超时了。。。哪位大牛帮忙讲解一下,不甚感激。。(内附代码)#include<iostream> using namespace std; char value[60005]; int main(){ int i, j, k, score, record = 0; int num[7]; score = 0; for(i = 1; i <= 6; ++i){ scanf("%d", num + i); score += i * num[i]; } while(score){ if(score % 2 != 0) printf("Collection #%d:\nCan't be divided.\n\n", ++record); else{ score /= 2; memset(value, 0, sizeof(value)); value[0] = 1; for(i = 1; i <= 6; ++i){ for(j = 1; j <= num[i]; ++j) for(k = score; k >= i; --k) value[k] = (value[k] || value[k - i]); } if(value[score]) printf("Collection #%d:\nCan be divided.\n\n", ++record); else printf("Collection #%d:\nCan't be divided.\n\n", ++record); } score = 0; for(i = 1; i <= 6; ++i){ scanf("%d", num + i); score += i * num[i]; } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator