CodeForces
来源:互联网 发布:博客源码下载 编辑:程序博客网 时间:2024/05/17 05:59
题意:
给出一个图的邻接矩阵,要求给每个点赋值,使得点权和为k,并定义每条边权值为两端点点权的乘积,要求最大化边的权值和。
思路:
最大化边权值之和将k均分给图中的最大团中的每个点,即ans=k^2*(best-1)/(2*best)。
证明过程:Here we go
代码:
#include <bits/stdc++.h>using namespace std;const int maxn = 45;bool mp[maxn][maxn];int some[maxn][maxn], none[maxn][maxn], all[maxn][maxn];int n, k, ans;void dfs(int d, int an, int sn, int nn){if(!sn && !nn) ans = max(ans, an);int u = some[d][0];for(int i = 0; i < sn; ++i){int v = some[d][i];if(mp[u][v]) continue;for(int j = 0; j < an; ++j)all[d+1][j] = all[d][j];all[d+1][an] = v;int tsn = 0, tnn = 0;for(int j = 0; j < sn; ++j)if(mp[v][some[d][j]])some[d+1][tsn++] = some[d][j];for(int j = 0; j < nn; ++j)if(mp[v][none[d][j]])none[d+1][tnn++] = none[d][j];dfs(d+1, an+1, tsn, tnn);some[d][i] = 0, none[d][nn++] = v;}}void work(){ans = 0;for(int i = 0; i < n; ++i) some[1][i] = i+1;dfs(1, 0, n, 0);}int main(){scanf("%d %d", &n, &k);for(int i = 1; i <= n; ++i)for(int j = 1; j <= n; ++j){int x; scanf("%d", &x);mp[i][j] = x;}work();double res = k*k*1.0*(ans-1)/ans/2;printf("%.10f\n", res);return 0;}
继续加油~
阅读全文
1 0
- codeforces~~~
- Codeforces
- codeforces
- Codeforces
- codeforces
- codeforces
- Codeforces
- Codeforces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- BZOJ2696: 航班安排
- makefile的编写
- 第七届河南理工大学程序设计大赛(正式赛)
- 随时插入待办事项的todonotes宏包
- 正则表达式
- CodeForces
- 怎么让 Android 程序一直后台运行,像 QQ 一样不被杀死?
- 数据结构-树和二叉树
- 【HPU】 1194 Judge【快速幂取模】【模板】
- Window.location.Reload()和window.location.href 区别
- springMVC @ResponseBody HandlerInterceptor ModelAndView null
- Spring整合hibernate框架
- oracle 建表类型以及约束
- 位运算--集合的整数表示