UVA 11008 Antimatter Ray Clearcutting(DP)
来源:互联网 发布:妇科检查 知乎 编辑:程序博客网 时间:2024/06/08 08:54
It's year 2465, and you are the Chief Engineer for Glorified Lumberjacks Inc. on planet Trie. There is a number of trees that you need to cut down, and the only weapon you have is a high-powered antimatter ray that will cut through trees like butter. Fuel cells for the antimatter ray are very expensive, so your strategy is: stand somewhere in the forest and shoot the ray in some chosen direction. This will cut down all the trees that lie on the line in that direction. Given the locations of several trees and the number of trees that you are required to cut, what is the minimum number of shots that you need to fire?
Input
The first line of input gives the number of cases, N (at most 20). N test cases follow. Each one starts with 2 lines containing the integersn (the number of trees in the forest, at most 16) and m (the number of trees you need to cut, at most n). The next n lines will each give the (x,y) coordinates of a tree (integers in the range [-1000, 1000]).
Output
For each test case, output the line "Case #x:", where x is the number of the test case. On the next line, print the number of antimatter ray shots required to cut down at least m trees. Print an empty line between test cases.
Sample Input Output for Sample Input
2
4
4
0 0
0 1
1 0
1 1
9
7
0 0
1 1
0 2
2 0
2 2
3 0
3 1
3 2
3 4
Case #1:
2
Case #2:
2
Notes
In the first test case, you can cut down 4 trees by standing at (0, -1) and firing north (cutting 2 trees) and then standing at (1, -1) and again firing north (cutting 2 more trees).
In the second test case, you should stand at (3,-1) and fire north (cutting 4 trees) and then stand at (-1, -1) and fire north-east (cutting 3 more trees).
#include<cstdio>#include<cstring>#include<algorithm>#include<vector>#include<string>#include<iostream>#include<queue>#include<cmath>#include<map>#include<stack>#include<bitset>using namespace std;#define REPF( i , a , b ) for ( int i = a ; i <= b ; ++ i )#define REP( i , n ) for ( int i = 0 ; i < n ; ++ i )#define CLEAR( a , x ) memset ( a , x , sizeof a )typedef long long LL;typedef pair<int,int>pil;const int INF = 0x3f3f3f3f;int dp[(1<<20)+10];int x[25],y[25];int t,n,m;int num=0;bool ok(int i,int j,int k){ int xx1=x[i]-x[j],yy1=y[i]-y[j]; int xx2=x[j]-x[k],yy2=y[j]-y[k]; return xx1*yy2==xx2*yy1;}int solve(int re,int st){ if(dp[st]!=INF) return dp[st]; if(re==1) return dp[st]=1; if(re<=0) return 0; for(int i=0;i<n;i++) { if(st&(1<<i)) continue; for(int j=i+1;j<n;j++) { if(st&(1<<j)) continue; int cnt=2,s=st; s|=(1<<i);s|=(1<<j); for(int k=0;k<n;k++) { if(k==i||k==j) continue; if(st&(1<<k)) continue; if(ok(i,j,k)) { s|=(1<<k); cnt++; } } dp[st]=min(dp[st],solve(re-cnt,s)+1); } } return dp[st];}int main(){ int cas=1; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); REP(i,n) scanf("%d%d",&x[i],&y[i]); CLEAR(dp,INF); printf("Case #%d:\n%d\n",cas++,solve(m,0)); if(t) puts(""); } return 0;}/**/
- UVA 11008 Antimatter Ray Clearcutting(DP)
- Antimatter Ray Clearcutting - UVa 11008 状压dp
- UVA 11008 Antimatter Ray Clearcutting 状压DP
- uva 11008 - Antimatter Ray Clearcutting(状态dp)
- UVa 11008 - Antimatter Ray Clearcutting(状态压缩dp)
- uva 11008 Antimatter Ray Clearcutting
- uva 11008 Antimatter Ray Clearcutting
- UVA 11008 Antimatter Ray Clearcutting
- UVA 11008 Antimatter Ray Clearcutting
- UVA - 11008 Antimatter Ray Clearcutting
- uva 11008 Antimatter Ray Clearcutting
- uva 11008 - Antimatter Ray Clearcutting
- UVA 11008 Antimatter Ray Clearcutting
- UVA - 11008 Antimatter Ray Clearcutting
- UVA - 11008 Antimatter Ray Clearcutting
- uva 11008 Antimatter Ray Clearcutting
- UVa 11008 Antimatter Ray Clearcutting / 状态压缩DP
- Uva 11008 - Antimatter Ray Clearcutting 状态压缩
- Notepad++: Problem: Edit json file
- Eclipse项目迁移到AndroidStudio(一)
- 系统分析师笔记-数据库
- Ruby on Rails 简介。来自于一个台湾网站,某些术语与大陆翻译不同
- jpa @Enumerated
- UVA 11008 Antimatter Ray Clearcutting(DP)
- C#基础知识——01
- 小马哥--高仿华为p7 拆机主板型号X5 主板图与开机界面图 分版本 分日期。具体看图
- HTTP Digest authentication
- JAVA 类集
- 快速排序quick sort
- POJ - 3342 Party at Hali-Bula 树形DP
- java-I/O File类(5)-Reader和Writer、OutputStreamWriter 、BufferedWriter、字节流和字符流的区别
- linux C函数之stat函数