有N个正整数,需要从中选出一些数,使这些数的和最大。
若两个数a,b同时满足以下条件,则a,b不能同时被选
1:存在正整数C,使a*a+b*b=c*c
2:gcd(a,b)=1
Sample Output22
Input
第一行一个正整数n,表示数的个数。n<=3000
第二行n个正整数a1,a2,...an
Output
最大的和
Sample Input5
3 4 5 6 7
首先可以发现,只有奇数和偶数才可能满足上面两个条件;那么我们把序列分为奇偶两部分;设源点st,汇点ed;st 和奇数连边,ed 和偶数连边;那么我们遍历可能的连边,O(n^2);这个连边权值设为 inf;(有点最大权闭合子图的意思?那么我们求最小割即可;最后就是sum-dinic();
#include
#include
#include
#include
#include
#include
#include
#include
EPFL - Fighting