24h購物| | PChome| 登入
2013-04-09 07:46:19| 人氣595| 回應0 | 上一篇 | 下一篇

[UVA] 10264 - The Most Potent Corner

推薦 0 收藏 0 轉貼0 訂閱站台


 Problem B: The Most Potent Corner 

Problem

Every corner of the N-dimensional (1< N<15) unit cube has weight (some positive integer less than 256). We will call two corners neighbouring, if they have common edge. Potency of the corner is the sum of weights of all neighbouring corners. Weights of all the corners are given. You are to determine two neighbouring corners that have the maximum sum of potencies and to output this sum.

Input

The input will consist of several input blocks. Each input block begins with the integer N, the dimension of the cube. Then there are weights of the corners, one per line in the natural order: the first line contains the weight of the corner (0,...0,0,0), the second one - the weight of (0,...,0,0,1), then there is the weight of (0,...,0,1,0), then (0,...,0,1,1), then (0,...,1,0,0), the penultimate line contains the weight of the corner (1,...,1,1,0), the last one - (1,...,1,1,1).

The input is terminated by <EOF>.

Output

For each input block the output line should contain one number, the maximum potencies sum.

Sample Input

3
82
73
8
49
120
44
242
58
2
1
1
1
1

Sample Output

619
4


這題背景知是要稍微有一些,否則是看不懂題目的。
N 為空間的正N體,具有 2^N 個點,而每個點與點之間只會差一個 bit。

#include <stdio.h>
#include <string.h>
int main() {
int w[65536], x[65536], n;
while(scanf("%d", &n) == 1) {
int i, j, k = 1<<n;
for(i = 0; i < k; i++)
scanf("%d", &w[i]);
memset(x, 0, sizeof(x));
for(i = 0; i < k; i++) {
for(j = 0; j < n; j++)
x[i] += w[i^(1<<j)];
}
int ans = 0;
for(i = 0; i < k; i++) {
for(j = 0; j < n; j++) {
if(ans < x[i]+x[i^(1<<j)])
ans = x[i]+x[i^(1<<j)];
}
}
printf("%d\n", ans);
}
return 0;
}

台長: Morris
人氣(595) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA][math] 11254 - Consecutive Integers
此分類上一篇:[UVA][AC自動機] 1254 - Top 10

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文