LightOj 1018 Brush (IV) 状压dp
来源:互联网 发布:淘宝卖家详情页尺寸 编辑:程序博客网 时间:2024/05/22 07:15
题目大意: 有n个灰尘, 给出坐标, 吸尘器每次可以清理一条线上的全部灰尘, 问最少需要画几条线将全部灰尘覆盖。
一开始理解错题意了以为下一次画线的起点必须是上一次的终点Orz 后来发现每一次都可以随意确定起点终点。 所以直接就更简单了, 01代表这个灰尘是否还存在。
由于画线是任意的, 所以可以随意取一个点 然后枚举另一个点然后用这两个点画线(这里的随意具体到代码就是找到该状态的第一个1)。
实现起来并不难,代码如下:
#include <set>#include <map>#include <queue>#include <stack>#include <cmath>#include <string>#include <cctype>#include <cstdio>#include <cstdlib>#include <cstring>#include <iomanip>#include <sstream>#include <iostream>#include <algorithm>using namespace std;#define ls id<<1,l,mid#define rs id<<1|1,mid+1,r#define OFF(x) memset(x,-1,sizeof x)#define CLR(x) memset(x,0,sizeof x)#define MEM(x) memset(x,0x3f,sizeof x)typedef long long ll ;typedef pair<int,int> pii ;const int maxn = 1e5+50 ;const int inf = 0x3f3f3f3f ;const int MOD = 1e9+7 ;int T,n,is_line[20][20];int dp[1<<16];struct pnt{ int x,y;} p[20];bool check(int a,int b,int c) { return (p[b].x - p[a].x) * (p[c].y - p[b].y) == (p[c].x - p[b].x) * (p[b].y - p[a].y) ;}void init(){ CLR(is_line); for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { for (int k = 0; k < n; k++) { if (check(i,j,k)) is_line[i][j] |= 1 << k ; } } }}int dfs(int s) { int cnt = __builtin_popcount(s); if (cnt == 0) return 0; if (cnt <= 2) return 1; int &res = dp[s]; if (res != inf) return res;// cout << id << "\n" ; int i = 0; while ((s >> i & 1)== 0) i++; for (int j = i + 1; j < n; j++) { if (!(s >> j & 1)) continue ;// cout << s1 << " " << s << "\n" ; res = min(res, dfs(s ^ (s & is_line[i][j])) + 1); } return res;}int main () {#ifdef LOCALfreopen("C:\\Users\\Administrator\\Desktop\\in.txt","r",stdin);// freopen("C:\\Users\\Administrator\\Desktop\\out.txt","w",stdout);#endif scanf("%d",&T); int cas = 1; while (T--) { MEM(dp); printf("Case %d: ",cas++);// cout << "T==" << T << "\n" ; scanf("%d",&n); for (int i = 0; i < n; i++) { scanf("%d%d",&p[i].x,&p[i].y); } init(); printf("%d\n",dfs((1 << n) - 1)); }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)
- [light oj 1018]Brush(IV)[状压DP]
- [light oj 1018]Brush(IV)[状压DP]
- lightoj 1018 brush(四)(状压DP)
- lightoj1018 - Brush (IV)【状压dp】
- LightOJ 1018 - Brush (IV)(记忆化搜索)
- LightOJ 1017 Brush (III) (DP)
- SQL数据库面试题以及答案
- c++ 副本构造器
- UIBezierPath 使用
- bash中使用文件锁
- 避免servlet 在并发下线程安全问题
- LightOj 1018 Brush (IV) 状压dp
- cadance约束设计小细节
- actionbar
- 计蒜客 第8题:字符串长度
- 安卓view.getMeasuredHeight()得到的高度单位以及dp和px的转换
- Reveal查看第三方app UI视图
- Amazon S3 云存储服务简介
- 传智播客对大学的期许
- div+css布局问题:设置浮动后的div高度变化后不超出最外层div