February 28- fifth class machine test record

Violence Enumeration

pit

  • Multiple use vis remember to empty

Ideas and summary

  • Dichotomy can optimize many

  • Use dfs violent search operations to know the relationship between the two recursive and recursive time when the conduct of a reasonable set of parameters to achieve certain objectives

  • To be able to identify violent search, some things seem to have a law, but the law does not actually have to discuss, direct violence can be achieved, this approach tends to be ignored

  • Violence does not mean brute force, but also a place optimization, sometimes to prevent repeat enumerate
    • Sometimes need to be considered for an enumeration violent way but simpler and easier to enumerate
    • Violence can also reduce the number of enumerated by setting the appropriate order
  • Binary enumeration few tips

    //枚举0-2^n - 1
    int len;
    for(int i = 0; i <(1 << len); i ++){
      //1<<len 即为 2^n
    }
    
    //取每一位为1进行对于操作
    for(int i = 0; i < len; i ++){
      if(num & (1 < i)){//num为长度为len的数字,1<i进行移位操作,然后使用&就可以获得对应位的二进制了
    
      }
    }
    

operation

  • 1108

    • Pretreatment play table

    • Use unique set of optimization results

    • Find dichotomy collection order

      sort(arr, arr + n);
      int size = unique(arr, arr + n) - arr;//unique返回的是排序后多余的下标
      //如 1 2 2 3 4 4 => 1 2 3 2 4 会返回指向第二个2的指针,因此相剪就会变成排序后的长度,再重新利用arr就可以使用去重后的数列
  • 1063

    • Å formula primes the Method of playing table, and then determine palindromic

    • Prefix number using a pretreatment section to quickly find and

      //打表法求素数
      bool p[N];//false为素数
      void init(){
          memset(p, 0, sizeof(p));
          p[1] = [1];//1不是素数
          for(int i = 2; i < N; i ++){
              if(! p[i]){
                  for(long long j = 1ll * i * i; j < N; j += i){//1.使用longlong,2.递增是+i,不是+1
                      p[j] = true;
                  }
              }
          }
      }
      
      //使用前缀和
      int pre[N];
      for(int i = 1; i < N; i ++){
          if(! p[i] && check(i))
              sum[i] = sum[i - 1] + 1;
          else
              sum[i] = sum[i - 1];
      }

Question number

  • PIPIOJ 1130: Parity staggered

  • PIPIOJ 1133: chessboard

  • PIPIOJ 1138: N Queens Problem

  • PIPIOJ 1102: PIPI school additions

  • The button PIPI Ⅰ: PIPIOJ 1049

  • PIPIOJ 1066: vertical issues

  • PIPIOJ 1322: Concentric Build China Dream

  • PIPIOJ 1084: the longest common subsequence Ⅱ

  • PIPIOJ 1168: PIPI squares

analysis

  • 1130
    • And all of the preprocessing, and then using a binary lookup
  • 1133
    • There are optimized to enumerate here, in order to prevent repetition of the enumeration, more skills that can be set on the parameter, this is the question I parameter settings selected after a point, after the enumeration only enumerate points behind, in fact, more preferred is to operate with a line
  • 1138
    • Classic n queens problem, but here vis array can be extended to primary and secondary diagonal
  • 1102
    • There is a de-emphasis technique, that is, when dfs backtracking, to remove the same number, to prevent repeat enumerate
  • 1049
    • Secondly, I began to think that the two dfs, think not quite right, because ans answer for the output array, the two dfs all of this operation, it should be understood as a layer of fishes, by setting the parameter start, to limit the starting point for the beginning of the enumeration, so that dfs has a different meaning
  • 1084
    • Find longest common subsequence, did not want to come out, the answer is given here using binary simulation, violence enumerate all of the sequences, the use of hashmap save, character after another, each time the enumeration sequence to see map queries to it, if it is saved to a temporary found the map, then use the temporary map to update hashmap, to make the sequences obtained to be updated every time, gradually shortened
    • For a plurality of possible outcomes, but the minimum need to lexicographically but also the longest length, in the last cycle, the sub-sequence in the length hashmap determination, if the same length were determined lexicographically
    • Cyclic character processing techniques, s + = s; expanded into double
  • 1168
    • If the direct enumeration phalanx of state violence, inappropriate, considering that the first line is determined, while the remaining will be determined, and therefore can be used as the first line of binary enumeration, then the first row is intended to determine whether the Matter (Note that the last line but also to determine once, because the cycle just before the last line generated, and finally the legitimacy of the need for additional line out to determine)

Guess you like

Origin www.cnblogs.com/faberry/p/12380425.html