U E D R , A S I H C RSS

1R/2016_09_11 (rev. 1.8)

1R/2016_09_11



1. 오늘의 문제

2. 참가자

3. 코드

3.1. 15이원준

#include<iostream>
#include<stdio.h>
#include<vector>

using namespace std;

int main(){
      vector<int> in;
      vector<int> vec;
      int N;
      scanf("%d", &N);
      int size;
      size = N * (N + 1) / 2;
      for(int i = 0; i<size; i++){
        int temp;
        scanf("%d", &temp);
        in.push_back(temp);
      }
      vec.resize(size, 0);
      int i = 0;
      vec[0] = in[0];
      for(int j = 1; j<N; j++){ //줄 변경
        for(int m = 0; m<j; m++){ //m번째 줄 전부 탐색
          for(int k = 0; k < 2; k++){ //아왼, 아오
            if(vec[i + k + j] < vec[i] + in[i + k + j])
              vec[i + k + j] = vec[i] + in[i + k + j];
          }
          i++;
        }
      }
      int max = 0;
      for(int j = size-N; j <size; j++){
        if(max < vec[j]){
          max = vec[j];
        }
      }
      printf("%d\n", max);
}

3.2. 박인서

#include <iostream>
#include <algorithm>
int a[501][501], dp[501][501];

int main() {
	int n;

	std::cin >> n;
	for (int i = 0; i<n; i++) {
		for (int j = 0; j <= i; j++) {
			std::cin >> a[i][j];
		}
	}

	dp[0][0] = a[0][0];
	for (int i = 1; i<n; i++) {
		dp[i][0] = dp[i - 1][0] + a[i][0];
		for (int j = 1; j<i; j++) {
			dp[i][j] = std::max(dp[i - 1][j - 1], dp[i - 1][j]) + a[i][j];
		}
		dp[i][i] = dp[i - 1][i - 1] + a[i][i];
	}

	int max = 0;
	for (int i = 0; i<n; i++) {
		if (max<dp[n - 1][i]) max = dp[n - 1][i];
	}

	std::cout << max;
	return 0;
}

3.3. 곽정흠

미완
#include <stdio.h>

typedef struct {
	int num;
	int maxSum;
}node;

node tri[500][500];

int main() {
	int n;
	int maxRoute;
	scanf("%d", &n);

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < i + 1; j++) {
			
			if (i == 0 && j == 0) {
				tri[i][j].maxSum = tri[i][j].num;
			}
			
			scanf("%d", &(tri[i][j].num));
			
			if (j != 0 && j != i) {
				if (tri[i - 1][j - 1].maxSum>tri[i - 1][j].maxSum) {
					tri[i][j].maxSum = tri[i - 1][j - 1].maxSum + tri[i][j].num;
				}
				else {
					tri[i][j].maxSum = tri[i - 1][j].maxSum + tri[i][j].num;
				}
			}else if(j!)
		}
	}
}

4. 아이디어

4.1. 15이원준

4.2. 박인서

4.3. 곽정흠

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:22:06
Processing time 0.0548 sec