2018년 10월 24일 수요일

브루트 포스 알고리즘 (백준 9095번)

브루트 포스

모든 경우의 수를 다 해봄
무식한방법 , 메모리 많이 소비, 100% 풀수있음





정수 n을 주어졌을 때 1, 2, 3의 합으로 만들 수 있는 경우의 수?

1. n을 다 1로 더함
2. n-2에서 2를 더함
3. n-3에서 3을 더함

-> n-1, n-2, n-3을 알면 됨
-> 재귀함수로 해결

import java.util.Scanner;
public class Main {
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  int n = 0;
  int T;
  Scanner sc = new Scanner(System.in);
  T=sc.nextInt();
  for(int i=0;i<T;i++) {
  n=sc.nextInt();
  int c = bru(n);
  System.out.println(c);
  }
 }
 static int bru(int n) {
  if(n==0)return 1;
  int c=0;
  c=c+bru(n-1);
  if(n>=2)c=c+bru(n-2);
  if(n>=3)c=c+bru(n-3);

  return c;
 }
}

flutter 기본 개념 1

  Scaffold  - 화면 뼈대 역할  - 기본적으로 AppBar body floatingActionButton 같은걸 배치해줌  return Scaffold (       appBar : AppBar ( title : const Text ...