Title: Have m luggage each with a weight, divided into two cars asked whether the weight evenly.
Analysis: dp,01 backpack. Take the sum of half 01 backpacks.
Description: Long time did not do DP.
#include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include < Cstdio> #include <cmath>using namespace Std;int w[22],f[202];int main () {int N;char ch;while (~scanf ("%d%c ", &n,&ch)) while (n--) {int count = 0,sum = 0;while (~scanf ("%d%c ", &w[count],&ch) && ch = =") su M + = W[count ++];sum + = w[count ++];for (int i = 0; I <= sum; + + i) f[i] = 0;f[0] = 1;for (int i = 0; i < count; + + I ) for (int j = sum; J >= W[i];--j) if (F[j-w[i]]) f[j] = 1;if (sum%2 | |!f[sum/2]) printf ("no\n"); else printf ("yes\n"); return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
UVa 10664-luggage