zoukankan      html  css  js  c++  java
  • [ CodeVS冲杯之路 ] P1011

     不充钱,你怎么AC

           题目:http://codevs.cn/problem/1011/

     

           一开始以为是道数学题,列出了一个公式

           后面验证,发现只能推出第一次,后面的还需要迭代,推翻这个公式

           又去瞟了一眼数据范围,只有1000,显然直接暴力DFS

           每层直接从0枚,如果该层是0直接ans++

     

           时间复杂度O(nlog2n)

     1 #include<cstdio>
     2 #include<cstdlib>
     3 #include<cstring>
     4 #include<cmath>
     5 #include<iostream>
     6 #include<algorithm>
     7 using namespace std;
     8 
     9 int n,ans;
    10 void dfs(int x)
    11 {
    12     if (x==0)
    13     {
    14         ans++;
    15         return;
    16     }
    17     int i;
    18     for (i=0;i<=x/2;i++) dfs(i);
    19 }
    20 int main()
    21 {
    22     scanf("%d",&n);
    23     ans=0;
    24     dfs(n);
    25     printf("%d
    ",ans);
    26     return 0;
    27 }
  • 相关阅读:
    POJ 3009
    POJ 3253
    POJ 3617
    POJ 3984
    UVA10012
    HDU5100
    HDU 5101
    UVA301 运输
    UVA 331 交换的方案数
    uva 10344 算23点
  • 原文地址:https://www.cnblogs.com/hadilo/p/5859791.html
Copyright © 2011-2022 走看看