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

然后嘞,爆搜一次就能够

最后嘞,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. [HTML] 如何使用robots.txt防止搜索引擎抓取页面

    Robots.txt 文件对抓取网络的搜索引擎漫游器(称为漫游器)进行限制.这些漫游器是自动的,在它们访问网页前会查看是否存在限制其访问特定网页的 robots.txt 文件.如果你想保护网站上的某些 ...

  2. MySQL常见数据库引擎及比较

    一:MySQL存储引擎简介 MySQL有多种存储引擎,每种存储引擎有各自的优缺点,大家可以择优选择使用:MyISAM.InnoDB.MERGE.MEMORY(HEAP).BDB(BerkeleyDB) ...

  3. 移动测试基础—adb、monkey命令

    最近打算把移动测试相关的知识总结一下,先从基础开始吧,总结一下adb.monkey命令 adb常用命令总结 adb / adb -help 使用帮助 adb devices 查看连接到电脑的设备 ad ...

  4. python 飞机大战 实例

    飞机大战 #coding=utf-8 import pygame from pygame.locals import * import time import random class Base(ob ...

  5. AtCoder Regular Contest 069

    1. C - Scc Puzzle 计算scc的个数,先判断s个数需要多少个cc,多的cc,每四个可以组成一个scc.注意数据范围,使用long long. #include<bits/stdc ...

  6. java中的访问修饰符2

    综上所述:protected强调的是子类,deafult强调的是本包,private强调的是本类,public强调的是开放性.

  7. C#自定义控件实现控件随窗口大小改变

    1.新建用户控件,取名MyForm. 2.将默认的UserControl改成Form 3.在类中添加以下代码 private float X, Y; //获得控件的长度.宽度.位置.字体大小的数据 p ...

  8. git基础讲解

    idea :https://blog.csdn.net/autfish/article/details/52513465 eclipse:https://blog.csdn.net/yang57266 ...

  9. css3媒介查询使用规则小结

    响应式布局可以为不同终端的用户提供更加舒适的界面和更好的用户体验,而且随着目前大屏幕移动设备的普及,用大势所趋来形容也不为过. 用一句话来说:使用同一套Html代码来适配不同设备和满足不同场景不同用户 ...

  10. Linux 命令查询系统负载信息

    linux uptime命令主要用于获取主机运行时间和查询linux系统负载等信息.uptime命令过去只显示系统运行多久.现在,可以显示系统已经运行了多长 时间,信息显示依次为:现在时间.系统已经运 ...