hdu 5031 Lines 爆搜
事实上嘞,这个线能够仅仅延伸一端
然后嘞,爆搜一次就能够
最后嘞,600-800ms过
本弱就是弱啊。你来打我呀……
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int a[100][100];
int n,m,ans;
bool dfs(int step)
{
int i,j,t,ii,jj,x,y,cnt,tx,ty;
t=0;
for(i=0;i<n;i++)
t=max(t,*max_element(a[i],a[i]+m));
if(step+t>=ans)
return 0;
if(t==0)
{
ans=step;
return 1;
}
for(i=0;i<n;i++)
for(j=0;j<m;j++)
{
if(a[i][j])
{
if(i==0)
{
for(ii=0;ii<n;ii++)
if(!a[ii][j])
break;
if(ii==n)
{
for(ii=0;ii<n;ii++)
a[ii][j]--;
if(dfs(step+1))
return 1;
for(ii=0;ii<n;ii++)
a[ii][j]++;
}
}
if(j==0)
{
for(ii=0;ii<m;ii++)
if(!a[i][ii])
break;
if(ii==m)
{
for(ii=0;ii<m;ii++)
a[i][ii]--;
if(dfs(step+1))
return 1;
for(ii=0;ii<m;ii++)
a[i][ii]++;
}
}
for(ii=i+1;ii<n;ii++)
for(jj=0;jj<m;jj++)
{
if(a[ii][jj]&&jj!=j)
{
x=ii-i;
y=jj-j;
cnt=0;
for(tx=i,ty=j;tx>=0&&tx<n&&ty>=0&&ty<m&&a[tx][ty];tx+=x,ty+=y)
cnt++;
if(tx>=0&&tx<n&&ty>=0&&ty<m||cnt<3)
continue;
for(tx=i,ty=j;tx>=0&&tx<n&&ty>=0&&ty<m&&a[tx][ty];tx+=x,ty+=y)
a[tx][ty]--;
if(dfs(step+1))
return 1;
for(tx=i,ty=j;tx>=0&&tx<n&&ty>=0&&ty<m;tx+=x,ty+=y)
a[tx][ty]++;
}
}
return 0;
}
}
}
int main()
{
int T,i,j,cnt;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
n++;m++;
cnt=0;
for(i=0;i<n;i++)
for(j=0;j<m;j++)
{
scanf("%d",&a[i][j]);
cnt+=a[i][j];
}
ans=min(14,cnt/3);
dfs(0);
printf("%d\n",ans);
}
}
Lines
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 817 Accepted Submission(s): 222
figure).

The number of lines passing though coordinate (i,j) is written in cell (i,j) in the right figure.(i,j both start from 0).
You are given the matrix written by your friend. You need to figure out the possible minimal number of lines your friend drew on the paper.
For each test case, the first line contains two integers n, m (1 ≤ n, m ≤ 50) representing the size of the grids on the paper. The following (n+1) × (m+1) numbers is what your friend writes. It is guaranteed that the number of lines your friend draws does not
exceed 14. Each line passes through integer coordinates at least three times.
1
5 4
0 1 0 0 1
0 1 0 1 0
2 1 1 0 0
0 3 1 0 0
1 1 1 0 1
0 1 0 1 0
4
hdu 5031 Lines 爆搜的更多相关文章
- HDU 4403 A very hard Aoshu problem(dfs爆搜)
http://acm.hdu.edu.cn/showproblem.php?pid=4403 题意: 给出一串数字,在里面添加一个等号和多个+号,使得等式成立,问有多少种不同的式子. 思路: 数据量比 ...
- hdu5355 思维+爆搜
pid=5355">http://acm.hdu.edu.cn/showproblem.php?pid=5355 Problem Description There are m sod ...
- 【 POJ - 1204 Word Puzzles】(Trie+爆搜|AC自动机)
Word Puzzles Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 10782 Accepted: 4076 Special ...
- UVA 2474 - Balloons in a Box 爆搜
2474 - Balloons in a Box 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&a ...
- 【BZOJ-1853&2393】幸运数字&Cirno的完美算数教室 容斥原理 + 爆搜 + 剪枝
1853: [Scoi2010]幸运数字 Time Limit: 2 Sec Memory Limit: 64 MBSubmit: 1817 Solved: 665[Submit][Status] ...
- POJ 1166 The Clocks (爆搜 || 高斯消元)
题目链接 题意: 输入提供9个钟表的位置(钟表的位置只能是0点.3点.6点.9点,分别用0.1.2.3)表示.而题目又提供了9的步骤表示可以用来调正钟的位置,例如1 ABDE表示此步可以在第一.二.四 ...
- hdu5323 Solve this interesting problem(爆搜)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Solve this interesting problem Time Limit ...
- hdu4536-XCOM Enemy Unknown(爆搜)
XCOM-Enemy Unknown是一款很好玩很经典的策略游戏. 在游戏中,由于未知的敌人--外星人入侵,你团结了世界各大国家进行抵抗.随着游戏进展,会有很多的外星人进攻事件.每次进攻外星人会选择3 ...
- poj1077 Eight【爆搜+Hash(脸题-_-b)】
转载请注明出处,谢谢:http://www.cnblogs.com/KirisameMarisa/p/4298840.html ---by 墨染之樱花 题目链接:http://poj.org/pr ...
随机推荐
- [Swift]注册并购买加入Apple开发者计划。提示: “你的支付授权失败。请核对你的信息并重试,或尝试其他支付方式。请联系你的银行”
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- 如何用jQuery实现div随鼠标移动而移动?(详解)----2017-05-12
重点是弄清楚如何获取鼠标现位置与移动后位置,div现在位置与移动后位置: 用jQuery实现div随鼠标移动而移动,不是鼠标自身的位置!!而是div相对于之前位置的移动 代码如下:(注意看绿色部分的解 ...
- Scrapy中的核心工作流程以及POST请求
五大核心组件工作流程 post请求发送 递归爬取 五大核心组件工作流程 引擎(Scrapy)用来处理整个系统的数据流处理, 触发事务(框架核心) 调度器(Scheduler)用来接受引擎发过来的请求, ...
- BZOJ 2659 数学
思路: 一开始以为是真·欧几里德 a,b来回消 (其实用不了那么麻烦) 我们发现 这是一个矩形 求一下整点数 完了.. 要特判 p=q的情况 //By SiriusRen #include <c ...
- Canvas实现环形进度条
Canvas实现环形进度条 直接上代码: <canvas width="200" height="200" >60%</canvas> ...
- ML及AI资源索引
原文链接:http://blog.csdn.net/pongba/article/details/2915005 机器学习与人工智能学习资源导引 TopLanguage(https://groups. ...
- LightOJ 1422 Halloween Costumes 【 区间dp 】
区间dp的第一题----- 看题解看了好多~~终于看懂了---55555 dp[i][j] 表示第i天到第j天至少需要多少件衣服 那么第i件衣服只被第i天占用的话, dp[i][j] = dp[i+1 ...
- 如何修改wifi为家庭网络
一不小心手快,把新链接的 wifi 选择成“公用网络”了,使用过程中导致某些应用无法联网,那个恨呐!!! 幸好,咱们可以进行手工更改,哈哈,跟哥一起来操作: 进入”网络与共享中心界面": 选 ...
- java中后端拼接字符串返回前台页面换行显示
后端拼接时用:"\n"分割,比如: String str = "白日依山尽,\n" + "黄河入海流:"; 返回前台页面时,放入 <p ...
- Java导出Excel文件的两种方法
将数据以Excel表格的形式导出:首先下载poi的jar包,导入项目中,或者使用maven仓库管理,在pom文件添加:<dependency> <groupId>org. ...