LightOJ - 1018 Brush (IV)(状态压缩DP)
来源:互联网 发布:微群控营销软件 编辑:程序博客网 时间:2024/06/15 02:37
题目大意:给你N个点,问需要画几条直线,才能将所有的点包括
解题思路:点数不大,可以状态压缩
先处理出所有在同一条线上的所有点,接着DP
因为画线的顺序是不用考虑的,前后没有差别的,所以我们可以直接以没有划线的第一个点为其中一点,接着找另一个没有被划到的,DP下去
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int N = 20;const int INF = 0x3f3f3f3f;const int M = (1 << 16) + 10;int x[N], y[N], line[N][N], dp[M], vis[M];int n, cas = 0;void init() { scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d%d", &x[i], &y[i]); for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) { line[i][j] = (1 << i) | (1 << j); for (int k = 0; k < n; k++) { if (i == k || j == k) continue; if ((y[k] - y[i]) * (x[k] - x[j]) == (y[k] - y[j]) * (x[k] - x[i])) line[i][j] |= (1 << k); } line[j][i] = line[i][j]; }}int DP(int s) { if (vis[s] == cas + 1) return dp[s]; int start = 0, num = 0; bool flag = false; for (int i = 0; i < n; i++) { if (s & (1 << i)) { if (!flag) start = i; flag = true; num++; } } if (num == 0 || num == 1) { vis[s] = cas + 1; return dp[s] = num; } int ans = INF; for (int i = start + 1; i < n; i++) if (s & (1 << i)) { int t = DP(s & (~line[start][i])) + 1; ans = min(ans, t); } vis[s] = cas + 1; return dp[s] = ans;}void solve() { int all = (1 << n) - 1; printf("Case %d: %d\n", ++cas, DP(all));}int main() { int test; scanf("%d", &test); while (test--) { init(); solve(); } return 0;}
0 0
- LightOJ - 1018 Brush (IV)(状态压缩DP)
- LightOJ 1018 Brush (IV)(状态压缩DP)
- [LightOJ 1018]Brush (IV)[状压DP]
- LightOj 1018 Brush (IV) 状压dp
- LightOJ 1018 - Brush (IV) (状压dp)
- [LightOJ 1018] Brush (IV) (状压DP)
- lightoj 1018 - Brush (IV) 状压DP
- lightoj 1018 - Brush (IV) 【状压dp】
- LIGHTOJ 1018 Brush (IV)
- LightOJ 1018 Brush (IV)
- LightOJ 1018 - Brush (IV)
- lightoj 1018 - Brush (IV)
- LightOJ1018- Brush (IV) -状态压缩,DFS
- [light oj 1018]Brush(IV)[状压DP]
- [light oj 1018]Brush(IV)[状压DP]
- lightoj 1018 (状态压缩DP)
- LightOJ 1018 - Brush (IV)(记忆化搜索)
- lightoj 1018 brush(四)(状压DP)
- HDU 3074 Multiply game
- C++从零实现BP神经网络
- 返回值修改input值 jquery
- HDU-1029 Ignatius and the Princess IV
- 适配器设计模式
- LightOJ - 1018 Brush (IV)(状态压缩DP)
- 月薪3万的程序员都避开了哪些坑
- hdu 4623 Crime(等价类+变进制哈希+状压dp)
- 图像直方图均衡化次数不同,结果相同简要说明
- Linux下缓冲区溢出攻击的原理及对策
- java 集合类说明及区别
- [Linux]cmake工具的使用
- LeetCode 094 Binary Tree Inorder Traversal
- Java设计模式之代理模式