ACM: 动态规划题 poj 3140
来源:互联网 发布:金山tw域名遭抢注 编辑:程序博客网 时间:2024/06/08 03:01
In the new ACM-ICPC RegionalContest, a special monitoring and submitting system will be set up,and students will be able to compete at their own universities.However there’s one problem. Due to the high cost of the newjudging system, the organizing committee can only afford to set thesystem up such that there will be only one way to transferinformation from one university to another without passing the sameuniversity twice. The contestants will be divided into twoconnected regions, and the difference between the total numbers ofstudents from two regions should be minimized. Can you help thejuries to find the minimum difference?
Input
There are multiple testcases in the input file. Each test case starts with two integersN and M, (1 ≤ N ≤ 100000, 1 ≤ M ≤1000000), the number of universities and the number of directcommunication line set up by the committee, respectively.Universities are numbered from 1 to N. The next line hasN integers, the Kth integer is equal tothe number of students in university numbered K. The numberof students in any university does not exceed 100000000. Each ofthe following M lines has two integers s, t,and describes a communication line connecting university sand university t. All communication lines of this new systemare bidirectional.
N = 0, M = 0 indicates the end of input and shouldnot be processed by your program.
Output
For every test case, output one integer, the minimum absolutedifference of students between two regions in the format asindicated in the sample output.
Sample Input
7 6
1 1 1 1 1 1 1
1 2
2 7
3 7
4 6
6 2
5 7
0 0
Sample Output
Case 1: 1
题意: ACM举办方要将全部参赛的学校分成2部分, 要求2部分的人分配尽量平均, 求出最小差值.
解题思路:
代码:
#include <cstdio>
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
#define MAX 200005
const __int64 temp = 1;
const __int64 INF = (temp<<61);
int n, m;
vector<int> g[MAX];
__int64 a[MAX];
__int64 dp[MAX], sum;
bool vis[MAX];
inline __int64 my_abs(__int64 a)
{
}
inline __int64 min(__int64 a, __int64 b)
{
}
void dfs(int u)
{
}
__int64 solve()
{
}
int main()
{
//
}
- ACM: 动态规划题 poj 3140
- ACM: 简单动态规划题 poj 2955
- ACM: 动态规划题 poj 2241
- ACM: 动态规划题 poj 1054
- ACM: 动态规划题 poj 2948
- ACM: 动态规划题 poj 1925
- ACM: 动态规划题 poj 3034
- ACM: 动态规划题 poj 2411
- ACM: 动态规划题 poj 1947
- ACM: 动态规划题 poj 2486
- ACM: 动态规划题 poj 3659
- ACM: 动态规划题 poj 2923
- ACM: dp动态规划题(难) poj 3267 …
- ACM: dp题(动态规划) poj 2151 (d…
- ACM: 树状DP 动态规划题 poj 1463 …
- ACM: 动态规划题 poj 2057 树状DP
- ACM:动态规划题 poj 1015
- ACM: 动态规划题 poj&nb…
- ACM: 动态规划题 poj 1185 想了两…
- windows.h
- ACM: 动态规划题 poj 2057 树状DP
- ACM: 动态规划题 poj 1947
- ACM: 动态规划题 poj 2486
- ACM: 动态规划题 poj 3140
- ACM: 动态规划题 poj&nb…
- ACM: 动态规划题 poj 1192 树形DP
- ACM: 动态规划题 poj 3659
- 动态规划: 经典0-1背包问题 (转)
- ACM: 动态规划题 poj&nb…
- ACM: 动态规划题 poj 3211 背包变…
- (OK)(OK) Fedora23——NS3(MANETs)——Docker(busybox)——genymotion(android)——All is OK
- ACM: 动态规划题 poj&nb…