总是T,以为要剪枝,后来发现加个map就行了

  1. #include<cstdio>
  2. #include<iostream>
  3. #include<algorithm>
  4. #include<cstring>
  5. #include<cmath>
  6. #include<queue>
  7. #include<map>
  8. using namespace std;
  9. #define MOD 1000000007
  10. const int INF=0x3f3f3f3f;
  11. const double eps=1e-;
  12. typedef long long ll;
  13. #define cl(a) memset(a,0,sizeof(a))
  14. #define ts printf("*****\n");
  15. const int MAXN=;
  16. int n,m,tt;
  17. bool vis[MAXN];
  18. int a[MAXN];
  19. bool dfs(int pos)
  20. {
  21. while(vis[pos]==&&pos>) pos--;
  22. if(pos==) return ;
  23. if(pos==)
  24. {
  25. return ;
  26. }
  27. int temp=pos-;
  28. for(int i=;i<=;i++)
  29. {
  30. if(temp<=) return ;
  31. if(vis[temp])
  32. {
  33. i--;
  34. temp--;
  35. continue;
  36. }
  37. if(a[pos]==a[temp]) //找到
  38. {
  39. vis[temp]=;
  40. if(dfs(pos-)) return ;
  41. vis[temp]=;
  42. }
  43. temp--;
  44. }
  45. return ;
  46. }
  47. int main()
  48. {
  49. int i,j,k,ca=;
  50. #ifndef ONLINE_JUDGE
  51. freopen("1.in","r",stdin);
  52. #endif
  53. while(scanf("%d",&n)!=EOF)
  54. {
  55. map<int,int> mp;
  56. for(i=;i<=n;i++)
  57. {
  58. scanf("%d",a+i);
  59. mp[a[i]]++;
  60. }
  61. if(n%)
  62. {
  63. printf("0\n");
  64. continue;
  65. }
  66. bool f=;
  67. map<int,int>::iterator it;
  68. for(it=mp.begin();it!=mp.end();it++)
  69. {
  70. if((it->second)%==)
  71. {
  72. f=;
  73. break;
  74. }
  75. }
  76. if(!f)
  77. {
  78. printf("0\n");
  79. continue;
  80. }
  81. cl(vis);
  82. printf("%d\n",dfs(n));
  83. }
  84. }

hdu 4272 2012长春赛区网络赛 dfs暴力 ***的更多相关文章

  1. hdu 4277 2012长春赛区网络赛 dfs+hashmap ***

    hashmap判重大法好 #include<cstdio> #include<iostream> #include<algorithm> #include<c ...

  2. hdu 4273 2012长春赛区网络赛 三维凸包中心到最近面距离 ***

    新模板 /* HDU 4273 Rescue 给一个三维凸包,求重心到表面的最短距离 模板题:三维凸包+多边形重心+点面距离 */ #include<stdio.h> #include&l ...

  3. hdu 4274 2012长春赛区网络赛 树形dp ***

    设定每个节点的上限和下限,之后向上更新,判断是否出现矛盾 #include<cstdio> #include<iostream> #include<algorithm&g ...

  4. hdu 4741 2013杭州赛区网络赛 dfs ***

    起点忘记录了,一直wa 代码写的很整齐,看着很爽 #include<cstdio> #include<iostream> #include<algorithm> # ...

  5. hdu 4412 2012杭州赛区网络赛 期望

    虽然dp方程很好写,就是这个期望不知道怎么求,昨晚的BC也是 题目问题抽象之后为:在一个x坐标轴上有N个点,每个点上有一个概率值,可以修M个工作站, 求怎样安排这M个工作站的位置,使得这N个点都走到工 ...

  6. hdu 4411 2012杭州赛区网络赛 最小费用最大流 ***

    题意: 有 n+1 个城市编号 0..n,有 m 条无向边,在 0 城市有个警察总部,最多可以派出 k 个逮捕队伍,在1..n 每个城市有一个犯罪团伙,          每个逮捕队伍在每个城市可以选 ...

  7. hdu 4293 2012成都赛区网络赛 dp ****

    题意:有n个人,可任意分成若干组,然后每个人个各提供一个信息,表示他们组前面有多少人,后面有多少人.问最多有多少个信息是不冲突的. 将n个人看成一组区间,然后每个人的信息可以表示为该人所在组的区间,然 ...

  8. hdu 4291 2012成都赛区网络赛 矩阵快速幂 ***

    分析:假设g(g(g(n)))=g(x),x可能非常大,但是由于mod 10^9+7,所以可以求出x的循环节 求出x的循环节后,假设g(g(g(n)))=g(x)=g(g(y)),即x=g(y),y也 ...

  9. hdu 4278 2012天津赛区网络赛 数学 *

    8进制转为10进制 #include<cstdio> #include<iostream> #include<algorithm> #include<cstr ...

随机推荐

  1. Metronic 与 VS2013/2015 合作开发

    Metronic 与 VS2013/2015 合作开发  去年购买了一个:METRONIC  (http://www.keenthemes.com/) ,最近下了最新的版本:V3.7 ,解压缩后,目录 ...

  2. Java for LeetCode 225 Implement Stack using Queues

    Implement the following operations of a stack using queues. push(x) -- Push element x onto stack. po ...

  3. 【leetcode】First Missing Positive(hard) ☆

    Given an unsorted integer array, find the first missing positive integer. For example,Given [1,2,0]  ...

  4. 【leetcode】Number of 1 Bits (easy)

    做太多遍了,秒杀. class Solution { public: int hammingWeight(uint32_t n) { ; ), num++); return num; } };

  5. 【leetcode】Happy Number(easy)

    Write an algorithm to determine if a number is "happy". A happy number is a number defined ...

  6. Linux 命令执行结果输出到屏幕的同时写入到文件中

    tee命令可以做到这一点: 例:ls -al /home | tee log 就可以把命令输出的内容显示在屏幕上的同时也输出至文件log.

  7. bootstrap添加时间控件

    $('#startTime').daterangepicker({ singleDatePicker: true,format:"YYYY-MM-DD HH:mm:ss",time ...

  8. Sql如何自动定时备份数据库

    直接上图

  9. 修改VS2010生成的dll文件中的内容

    我的电脑是64为的操作系统,所以先找到下面的路径 C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin 找到这个文件:ildasm.exe,如 ...

  10. 定时器(NSTimer)

    iOS中定时器NSTimer的使用 1.初始化 + (NSTimer *)timerWithTimeInterval:(NSTimeInterval)ti target:(id)aTarget sel ...