UVA Solution 435 - Block Voting - Solution in C, CPP
UVA Online Judge Solution 435 - Block Voting | Volume 4UVA Problem Link - https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=6&page=show_problem&problem=376
Problem Name: 435 - Block Voting
Problem Number : UVA - 435 - Block Voting
Online Judge : UVA Online Judge Solution
Volume: 4
Solution Language : C, C plus plus
UVA Solution 435 - Block Voting Code in C, CPP:
#include <stdio.h> int main() { int t, P, A[20], i, j, k; scanf("%d", &t); while(t--) { scanf("%d", &P); int sum = 0; for(i = 0; i < P; i++) scanf("%d", &A[i]), sum += A[i]; int half = sum/2 + (sum&1); for(i = 0; i < P; i++) { int DP[1001] = {}; DP[0] = 1; for(j = 0; j < P; j++) { if(i == j) continue; for(k = sum-A[j]; k >= 0; k--) DP[k+A[j]] += DP[k]; } int ans = 0; for(j = half-A[i]; j < half && j >= 0; j++) { ans += DP[j]; } printf("party %d has power index %d\n", i+1, ans); } puts(""); } return 0; }
Tags: UVA Online Judge Solution, UVA OJ Solution list, UVA Problems Solution, UVA solver, UVA all problem solution list, UVA Block Voting code in C, UVA 435 code in C++, UVA Block Voting solution in C, UVA 435 solution
No comments:
Post a Comment