链接

题意 : 看了好长时间终于看懂题目了,将一个大矩形划分成若干小矩形,告诉你每个小矩形的左上角那个点和右下角那个点的坐标,告诉你这个小矩形要涂的颜色,每个颜色对应一个刷子,问你最少要使用几次刷子。因为你要刷一个矩形之前,必须把这个矩形上方与之直接相邻的所有矩形先刷掉才能刷这个,如果你先用了红色的刷子,然后又用了蓝色的刷子,最后又用了红色的刷子,这算是3次使用而不是两次,样例中,用红色刷B所以D也可以刷了,用蓝色先刷A,然后可以刷C,因为B刷了所以E也可以刷了,最后换刷子把剩下的刷掉,总共三次。

思路 : 这个题可以用DFS也可以用状压DP,我用的DFS,因为没压出来,,,,,,,这里有分析,链接1链接2。先将每个矩形看成一个点,然后如果存在上下关系的话,下边那个点的入度+1,先找入度为0的点开始染色,如果这个点已经染掉了的话,那它下边的点入度要减1.。。。。。。。

  1. //
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <iostream>
  5.  
  6. using namespace std ;
  7.  
  8. struct rectangle
  9. {
  10. int lx,ly ;
  11. int rx,ry ;
  12. int R ;
  13. } rec[];
  14. int degree[] ;
  15. bool mapp[][],vis[] ;
  16. int M ,n;
  17. int cnt ;
  18.  
  19. void build()
  20. {
  21. memset(mapp,false,sizeof(mapp)) ;
  22. memset(degree,,sizeof(degree)) ;
  23. memset(vis,false,sizeof(vis)) ;
  24. for(int i = ; i < n ; i++)
  25. {
  26. for(int j = ; j < n ; j++)
  27. {
  28. if(i == j) continue ;
  29. else
  30. {
  31. if(rec[i].ly == rec[j].ry && !(rec[i].rx < rec[j].lx || rec[j].rx < rec[i].lx))
  32. {
  33. mapp[i][j] = true ;
  34. degree[i] ++ ;
  35. }
  36. }
  37. }
  38. }
  39. }
  40.  
  41. void DFS(int r,int ans,int step)
  42. {
  43. if(ans > cnt) return ;
  44. if(step == n)
  45. {
  46. cnt = ans ;
  47. return ;
  48. }
  49. for(int i = ; i < n ; i++)
  50. {
  51. if(!vis[i] && degree[i] == )
  52. {
  53. vis[i] = true ;
  54. for(int j = ; j < n ; j++)
  55. if(mapp[j][i])
  56. degree[j] -- ;
  57. if(rec[i].R == r ) DFS(r,ans,step+) ;
  58. else DFS(rec[i].R,ans + ,step+) ;
  59. vis[i] = false ;
  60. for (int j = ; j < n; j++)
  61. {
  62. if (mapp[j][i]) degree[j]++;
  63. }
  64. }
  65. }
  66. }
  67. int main()
  68. {
  69. scanf("%d",&M) ;
  70. while(M--)
  71. {
  72. scanf("%d",&n) ;
  73. for(int i = ; i < n ; i++)
  74. scanf("%d %d %d %d %d",&rec[i].ly,&rec[i].lx,&rec[i].ry,&rec[i].rx,&rec[i].R) ;
  75. build() ;
  76. cnt = ;
  77. DFS(,,) ;
  78. printf("%d\n",cnt) ;
  79. }
  80. return ;
  81. }

POJ 1691 Painting A Board(DFS)的更多相关文章

  1. POJ 1691 Painting a Board(状态压缩DP)

    Description The CE digital company has built an Automatic Painting Machine (APM) to paint a flat boa ...

  2. POJ 1691 Painting A Board(迭代深搜)

    题目链接 调了一上午,单步的效率太低了,特别是在有递归的情况下...下午来了,输出调试了下,就发现bug了,各种混乱啊. 比较高兴的事,1Y了.本来还准备用edge1优化一下的,结果完全没用到.. # ...

  3. 【拓扑排序】【DFS】Painting A Board

    [poj1691]Painting A Board Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3902   Accept ...

  4. POJ 1321-棋盘问题(DFS 递归)

    POJ 1321-棋盘问题 K - DFS Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I6 ...

  5. POJ 3321 Apple Tree(DFS序+线段树单点修改区间查询)

    Apple Tree Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 25904   Accepted: 7682 Descr ...

  6. POJ 1979 Red and Black dfs 难度:0

    http://poj.org/problem?id=1979 #include <cstdio> #include <cstring> using namespace std; ...

  7. POJ 2378 Tree Cutting (DFS)

    题目链接:http://poj.org/problem?id=2378 一棵树,去掉一个点剩下的每棵子树节点数不超过n/2.问有哪些这样的点,并按照顺序输出. dfs回溯即可. //#pragma c ...

  8. poj 1659 Frogs' Neighborhood (DFS)

    http://poj.org/problem?id=1659 Frogs' Neighborhood Time Limit: 5000MS   Memory Limit: 10000K Total S ...

  9. poj 2531 Network Saboteur( dfs )

    题目:http://poj.org/problem?id=2531 题意:一个矩阵,分成两个集合,求最大的 阻碍量 改的 一位大神的代码,比较简洁 #include<stdio.h> #i ...

随机推荐

  1. sql临时表和表变量

    1. 为什么要使用表变量 表变量是从2000开始引入的,微软认为与本地临时表相比,表变量具有如下优点:  a.与其他变量的定义一样,表变量具有良好的定义范围,并会被自动清除:  b.在存储过程中使用表 ...

  2. MySql安装时在Start Service处失败

    安装MySql时在最后Start Service时失败: 首先先卸载掉MySql. 查看MySql服务有没有启动,若启动,则先停止MySql服务.   打开注册表,到HKEY_LOCAL_MACHIN ...

  3. html5离线应用详摘

    html5离线应用详摘 在html文件里配置如下: <html manifest=”name.manifest”> 在name.manifest文件里配置如下: CACHE MANIFES ...

  4. 2013-07-26 IT 要闻速记快想

    ### ========================= ###传Google正在内测供用户买卖技能的电商平台Helpout,最早于下月上线该服务将依托Google强大的云服务和搜索能力,以实时视频 ...

  5. 通过百度地图API显示当前位置在地图上(图标显示)--第三方开源--百度地图(二)

    1.下载百度地图的demo,下载地址:http://lbsyun.baidu.com/sdk/download?selected=mapsdk_basicmap,mapsdk_searchfuncti ...

  6. Java从入门到精通——基础篇之Servlet与JSP的区别

    一.基本概念 1.1 Servlet Servlet是一种服务器端的Java应用程序,具有独立于平台和协议的特性,可以生成动态的Web页面.它担当客户请求(Web浏览器或其他HTTP客户程序)与服务器 ...

  7. wap_supplicant介绍

    目前可以使用wireless-tools 或wpa_supplicant工具来配置无线网络.请记住重要的一点是,对无线网络的配置是全局性的,而非针对具体的接口. wpa_supplicant是一个较好 ...

  8. 理解PHP 依赖注入|Laravel IoC容器

    看Laravel的IoC容器文档只是介绍实例,但是没有说原理,之前用MVC框架都没有在意这个概念,无意中在phalcon的文档中看到这个详细的介绍,感觉豁然开朗,复制粘贴过来,主要是好久没有写东西了, ...

  9. 微软职位内部推荐-Senior Dev Lead

    微软近期Open的职位: Bing Index Serve team is hiring! We are one of the core teams in Bing serving more than ...

  10. Error:No marked region found along edge. - Found along top edge.

    android开发的时候,初次使用.9图片出现以下: Error:No marked region found along edge. - Found along top edge. 原因: 如图:上 ...