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

然后嘞,爆搜一次就能够

最后嘞,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
2014 ACM/ICPC Asia Regional Guangzhou Online

hdu 5031 Lines 爆搜相关推荐

  1. UVA 2474 - Balloons in a Box 爆搜

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

  2. 2020杭电多校第二场 Lead of Wisdom(爆搜)

    Problem Description In an online game, "Lead of Wisdom" is a place where the lucky player ...

  3. 容斥 + 爆搜打表 ---- 2020年南京icpc H.Harmonious Rectangle

    题目链接 题目大意: 就是给你一个二维平面{(x,y)∣1≤x≤n,1≤y≤m}\{(x,y)|1\leq x\leq n,1\leq y \leq m\}{(x,y)∣1≤x≤n,1≤y≤m},你现 ...

  4. 1103 Integer Factorization (30 分)【难度: 中 / 爆搜】

    https://pintia.cn/problem-sets/994805342720868352/problems/994805364711604224 爆搜的做法,动态规划也可以做,有时间也一个动 ...

  5. 1096 Consecutive Factors (20 分)【难度: 一般 / 爆搜 数论】

    https://pintia.cn/problem-sets/994805342720868352/problems/994805370650738688 注意测试点1: 72=2*3*3*4 我这里 ...

  6. HDU - 6185 Covering(暴搜+递推+矩阵快速幂/杜教BM)

    题目链接:点击查看 题目大意:规定宽度为4,给定长度为n,求用1*2和2*1的瓷砖,将其完全铺满能有多少种方法. 分析:自从学会了矩阵快速幂之后,看到1e18的数据量都会下意识的往递推上面想,但是以前 ...

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

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

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

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

  9. 第46届icpc 沈阳 J-Luggage Lock(思维 + 爆搜 / 队友玄学出法, 还没看懂)

    第46届icpc 沈阳 J-Luggage Lock(思维 + 爆搜 / 队友玄学出法, 还没看懂) 题目来源:第46届icpc 沈阳 J-Luggage Lock 题意: 给出两个四位数的密码锁a和 ...

最新文章

  1. 【正一专栏】今晚国足能上演奇迹吗?
  2. linux挂载与卸载(转)
  3. win7光盘修复计算机在哪,win7如何创建系统还原及系统修复光盘功能应用
  4. Windows—JDK安装与环境变量配置
  5. javascript中call和apply的区别
  6. GIPC2018全球知识产权生态大会
  7. [Silverlight入门系列]动态创建控件和绑定
  8. std::thread的使用
  9. HarmonyOS 组件篇
  10. T5: Text-To-Text Transfer Transformer
  11. 惠普微型计算机怎么装机,台式小机惠普电脑怎么装系统
  12. vue-cropper 截图
  13. 7. Zigbee应用程序框架开发指南 - 时间处理
  14. [bzoj5332][bzoj5276][bzoj3994][莫比乌斯反演][三元环计数]旧试题/skyfall/约数个数和
  15. 中小企业如何选择OA协同办公产品?最全的对比都在这里了
  16. At least one JAR was scanned for TLDs yet contained no TLDs.问题解决方式
  17. 4/6 深搜、广搜专题+二分答案+单调队列
  18. Calcite的RelFieldTrimmer简介
  19. 节拍器在学习音乐过程中起到什么作用?-小星星节拍器怎么样?
  20. thread.sleep后没有恢复执行_申请法院强制执行很多年了,一直没有拿到钱,还能怎么办?...

热门文章

  1. WPF 用Main函数方式启动程序
  2. Web前端工程师应该掌握的内容有哪些
  3. Spark成为大数据高手进阶步骤
  4. WebService之Axis2 (3):使用services.xml文件发布WebService
  5. Windows PowerShell 2.0创建调用脚本文件
  6. uchome中的$_SC:系统全局配置
  7. 120万名 GoDaddy 客户数据遭泄露
  8. Fortinet 防火墙受高危漏洞影响,可遭远程攻击
  9. 又一起供应链攻击现身?投毒 Gigaset 更新,在手机注入恶意软件
  10. Hacker Plus:Facebook 推出漏洞奖励 “忠诚计划”