ZOJ1609-Equivalence
来源:互联网 发布:太空望远镜软件 编辑:程序博客网 时间:2024/06/15 03:56
When learning mathamatics, sometimes one may come to an theorem which goes like this:
The following statements are equivalent:
a)......
b)......
c)......
For example, let A be an angle between 0 and 360 degrees, the following statements are equivalent:
a)A = 90 degrees;
b)A is a right angle;
c)sin(A) = 1.
Proving such a theorem is usually a difficult task, because you have to prove that for any two statements Si and Sj, Si concludes Sj and vise versa. Sometimes, proving Si concludes Sj directly is quite difficult so we may find a Sk and prove that Si concludes Sk and Sk concludes Sj. Now given the difficulty of proving every Si => Sj, you are to calculate the minimal total difficulty to prove that the given statements are equivalent.
Input
The input contains several cases. Each case begins with an integer n (2 <= n <= 6), the number of statements in this case, followed by n lines, each contains n integers.
The jth integer of the ith row represents the difficulty of proving Si => Sj. The ith integer of the ith row is always 0 as it's obvious that Si concludes Si. All the n * n integers are between 0 and 100, inclusively. Input is terminated by EOF.
Output
For each test case, output a line with the minimal difficulty for that case.
Sample Input
4
0 2 3 4
5 0 7 8
9 10 0 12
13 14 15 0
Sample Output
34
Author: PAN, Minghao
Source: ZOJ Monthly, May 2003
题意:有n个点,告诉你两两之间有向边的权值,问使整张图强连通的最小权值为多少
解题思路:暴搜+剪纸+状态压缩
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <algorithm>#include <cmath>#include <map>#include <set>#include <stack>#include <queue>#include <vector>#include <bitset>using namespace std;#define LL long longconst int INF = 0x3f3f3f3f;const double pi = acos(-1.0);struct node{int x, y, sum;} xx[50];int n, cnt, mi,m;int a[10][10], b[50][8];bool cmp(node xx, node yy){return xx.sum < yy.sum;}void dfs(int x,int sum){if (sum >= mi) return;int res = 0;for (int i =0 ; i < n; i++){res += b[x][i] == m;b[x + 1][i] = b[x][i];}if (res==n){mi = min(mi, sum);return;}if(x==cnt) return ;for (int i = 0; i < n; i++){b[x + 1][i] = b[x][i];if (b[x][i] & (1 << xx[x].x)){b[x + 1][i] |= b[x][xx[x].y];}}dfs(x + 1, sum + xx[x].sum);for (int i = 0; i < n; i++) b[x + 1][i] = b[x][i];dfs(x + 1, sum);}int main(){while (~scanf("%d", &n)){cnt = 0;m = (1 << n) - 1;for (int i = 0; i < n; i++){for (int j = 0; j < n; j++){scanf("%d", &a[i][j]);if (i == j) continue;xx[cnt].x = i, xx[cnt].y = j, xx[cnt++].sum = a[i][j];}}sort(xx,xx+cnt,cmp);for (int i = 0; i < n; i++) b[0][i] = 1 << i;mi = INF;dfs(0, 0);printf("%d\n", mi);}return 0;}
- ZOJ1609-Equivalence
- Dynamic Equivalence in Translating
- ZOJ 1609Equivalence
- RAC User Equivalence Check Failed
- 等价类划分(Equivalence Partitioning)
- Sicily 2287. Expression Equivalence (optional)
- Equivalence of Emacs and Vim commands
- Configure SSH User Equivalence – Oracle RAC
- Configure SSH User Equivalence – Oracle RAC
- FEC 转发等价类 (Forwarding Equivalence Class)
- User equivalence unavailable on all nodes
- STL中相等(equality)与等价(equivalence)的区别
- 黑盒测试之等价划分法(Equivalence partitioning )
- STL中相等(equality)与等价(equivalence)的区别
- Fuzzy apllication (1): fuzzy cluster using fuzzy equivalence relation
- ISTQB Exam Questions on Equivalence partitioning and Boundary Value Analysis
- 什么是转发等价类(FEC, Forwarding Equivalence Class)
- Result: PRVF-4007 : User equivalence check failed for user "grid"
- USES_CONVERSION的使用和注意事项
- SpringMVC form:form的一个错误(没有传到前台绑定类)
- Bootstrap引用说明
- CSS 定位属性position
- 使用canvas绘制时钟
- ZOJ1609-Equivalence
- JAVA web项目跨域
- 4月16日预习函数
- 欢迎使用CSDN-markdown编辑器
- 腾讯云主机中MySQL无法远程连接的解决办法
- vscode几个常用插件推荐[补充]
- CURL模拟提交数据,TP暴力版
- PHP学习笔记——PHP变量的范围;
- SpringMvc使用Freemarker时的配置文件