事实上嘞,这个线能够仅仅延伸一端

然后嘞,爆搜一次就能够

最后嘞,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

Problem Description
You play a game with your friend. He draws several lines on the paper with n×m square grids (see the left figure). After that, he writes down the number of lines passing through every integer coordinate in a matrix (see the right
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.
 
Input
The first line of the input contains an integer T indicating the number of test cases( 0 < T <= 10).



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.
 
Output
For each test case, you need to output the minimal number of lines your friend drew on the paper in a single line.
 
Sample Input
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
 
Sample Output
4
 
Source
 

hdu 5031 Lines 爆搜的更多相关文章

  1. HDU 4403 A very hard Aoshu problem(dfs爆搜)

    http://acm.hdu.edu.cn/showproblem.php?pid=4403 题意: 给出一串数字,在里面添加一个等号和多个+号,使得等式成立,问有多少种不同的式子. 思路: 数据量比 ...

  2. hdu5355 思维+爆搜

    pid=5355">http://acm.hdu.edu.cn/showproblem.php?pid=5355 Problem Description There are m sod ...

  3. 【 POJ - 1204 Word Puzzles】(Trie+爆搜|AC自动机)

    Word Puzzles Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 10782 Accepted: 4076 Special ...

  4. UVA 2474 - Balloons in a Box 爆搜

    2474 - Balloons in a Box 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&a ...

  5. 【BZOJ-1853&2393】幸运数字&Cirno的完美算数教室 容斥原理 + 爆搜 + 剪枝

    1853: [Scoi2010]幸运数字 Time Limit: 2 Sec  Memory Limit: 64 MBSubmit: 1817  Solved: 665[Submit][Status] ...

  6. POJ 1166 The Clocks (爆搜 || 高斯消元)

    题目链接 题意: 输入提供9个钟表的位置(钟表的位置只能是0点.3点.6点.9点,分别用0.1.2.3)表示.而题目又提供了9的步骤表示可以用来调正钟的位置,例如1 ABDE表示此步可以在第一.二.四 ...

  7. hdu5323 Solve this interesting problem(爆搜)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Solve this interesting problem Time Limit ...

  8. hdu4536-XCOM Enemy Unknown(爆搜)

    XCOM-Enemy Unknown是一款很好玩很经典的策略游戏. 在游戏中,由于未知的敌人--外星人入侵,你团结了世界各大国家进行抵抗.随着游戏进展,会有很多的外星人进攻事件.每次进攻外星人会选择3 ...

  9. poj1077 Eight【爆搜+Hash(脸题-_-b)】

    转载请注明出处,谢谢:http://www.cnblogs.com/KirisameMarisa/p/4298840.html   ---by 墨染之樱花 题目链接:http://poj.org/pr ...

随机推荐

  1. RabbitMQ(三) 集群配置

    RabbitMQ--集群配置 之前不管是搞Redis.SQL.Mongo还是其他的东西,一律都没说过集群要怎么搞,电脑实在是带不动.说透彻点就是懒,懒得搭也懒得写,今日深刻意识到错误,做学问是不能懒的 ...

  2. MongoDB: The Definitive Guide

    第一章 简介 MongoDB是面向文档的数据库,不是关系型数据库.内置对MapReduce的支持,以及对地理空间索引的支持. 丰富的数据模型 容易扩展,它所采用的面向文档的数据模型可以使其在多台服务器 ...

  3. 通过Hibernate实现添加功能

    package com.demo.dao; import org.hibernate.Session; import org.hibernate.SessionFactory; import org. ...

  4. HTML5 audio 如何实现播放多个MP3音频

    <audio>标签是HTML5中的新标签,定义声音用于嵌入音频内容,比如音乐或其他音频流.用的比较多音频格式是.mp3. <audio>标签常用属性如下表 属性 值 描述 au ...

  5. 自定义SearchView实现即时查询

    1.效果图,输入关键字时会根据关键字改变而更新数据. 2.其布局文件和2个小图标del.png和searchview.png,布局文件如下:高度已固定为46dp. <?xml version=& ...

  6. todo reading

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_objects/Function/bind https ...

  7. Python Django中QQ邮箱授权码问题

    Python Django中QQ邮箱授权码问题 系统及软件版本如下: Ubuntu Kylin 16.04 Python 3.5.1 Django 1.9.7 PyCharm Community Ed ...

  8. Linux学习之路三:重要概念之Linux系统层次结构

    上图来自Unix编程圣经<APUE>英文第二版.如图,处于最中心的是系统内核,负责机器硬件资源管理,进程管理等:shell,函数库(值得记住的是C标准函数库)和某些应用程序均直接构建于内核 ...

  9. 创建一个dynamics CRM workflow (四) - Development of Custom Workflows

    首先我们需要确定windows workflow foundation 已经安装. 创建之后先移除MyCustomWorkflows 里面的 Activity.xaml 从packages\Micro ...

  10. 创建一个dynamics CRM workflow (六) - Debugging Custom Workflows

    我们也deploy部署了custom workflows, debugging是开发当中不可或缺的一个步骤. debug workflow的步骤和debug有些许不一样: 1. install pro ...