题解 | #称砝码#
称砝码
http://www.nowcoder.com/practice/f9a4c19050fc477e9e27eb75f3bfd49c
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#define MIN(a, b) ((a < b) ? (a) : (b))
static short g_int[2][10] = {0}; /* 0 行代表重量,1 行代表数量 */
static bool g_flag[200000] = {0}; /* 20w bit */
int main(int argc, char** argv)
{
int num, max = 0, acount = 0;
scanf("%d", &num); g_flag[0] = true;
for (int i = 0; i < 2; i++) for (int j = 0; j < num; j++) scanf("%hd", &g_int[i][j]);
for (int i = 0; i < num; i++) for (int j = 0; j < g_int[1][i]; j++) {
for (int k = max; k >= 0; k--) if (g_flag[k]) { g_flag[k + g_int[0][i]] = true; } max += g_int[0][i];
}
for (int i = 0; i <= max; i++) if (g_flag[i]) { acount++; } printf("%hd\n", acount);
return 0;
}