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

然后嘞,爆搜一次就能够

最后嘞,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. MySql查询系统时间,SQLServer查询系统时间,Oracle查询系统时间

    转自:https://blog.csdn.net/haleyliu123/article/details/70927668/ MySQL查询系统时间 第一种方法:select current_date ...

  2. day63-webservice 09.jquery调用ajax

    WebService可以有很多种调用方式,除了之前说的,还可以有jquery.拿原生的Ajax做调用,拿jquery怎么调用啊?原生的能调,jquery指定也能调.原生的Ajax是通过网页直接点HTM ...

  3. sublime的一些快捷键

    Sublime Text 3非常实用,但是想要用好,一些快捷键不可或缺,所以转了这个快捷键汇总. 用惯了vim,有些快捷键也懒得用了,尤其是在win下面,还有图形界面,所以个人觉得最有用的还是搜索类, ...

  4. thinkphp 具体常量,在view里面使用

    1 2 3 4 5 6 7 8 9 '__TMPL__'      =>  APP_TMPL_PATH,  // 项目模板目录 '__ROOT__'      =>  __ROOT__,  ...

  5. 关于打包压缩几种格式(gzip,bzip2,xz)的试验对比

    要通过脚本进行备份,必然将会应用到压缩技术,这里简单针对几个常见的格式进行测验,从而得到一种合适的方式. 这里以一个应用目录做例子: [root@isj-test-5 mnt]$du -sh * 66 ...

  6. 使用Micrisoft.net设计方案 前言

    前言 主要阐述23种设计模式在Microsoft.Net中的使用,以及使用设计模式创建后的对象如何使用.同是向我们传达3个理念,分别是: 1.  使用设计模式可以让程序更加灵活 2.  结构越复杂,意 ...

  7. [Offer收割]编程练习赛38

    漏写的数字 #pragma comment(linker, "/STACK:102400000,102400000") #include<stdio.h> #inclu ...

  8. 三维投影总结:数学原理、投影几何、OpenGL教程、我的方法

    如果要得到pose视图,除非有精密的测量方法,否则进行大量的样本采集时很耗时耗力的.可以采取一些取巧的方法,正如A Survey on Partial of 3d shapes,描述的,可以利用已得到 ...

  9. JavaScript创建对象的几种 方式

    //JavaScript创建对象的七种方式 //https://xxxgitone.github.io/2017/06/10/JavaScript%E5%88%9B%E5%BB%BA%E5%AF%B9 ...

  10. vc++如何创建程序--利用快捷键进行多行注释

    Eclipse同时注释多行①:ctrl+/或 ②:ctrl+shift+/ : Visual studio先按ctrl+k 再按 ctrl+c 2.在VC++6.0中需要自己设置快捷键,设置方法链接如 ...