U E D R , A S I H C RSS

1R/2016_09_11

Difference between r1.5 and the current

@@ -5,7 +5,8 @@

= 참가자 =
* 박인서
* 15이원준
* [곽정흠]
= 코드 =
== 15이원준 ==
{{{
@@ -83,7 +84,60 @@
}
}}}
== 곽정흠 ==
{{{
#include <stdio.h>
 
typedef struct {
int num;
int maxSum;
}node;
 
node tri[500][500];
 
int main() {
int n;
int maxRoute;
int maxFinal;
scanf("%d", &n);
 
for (int i = 0; i < n; i++) {
for (int j = 0; j <= i; j++) {
scanf("%d", &(tri[i][j].num));
 
if (i == 0 && j == 0) {
tri[i][j].maxSum = tri[i][j].num;
}
else {
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 == 0 && i != 0) {
tri[i][j].maxSum = tri[i - 1][j].maxSum + tri[i][j].num;
}
else if (j == i&&j != 0) {
tri[i][j].maxSum = tri[i - 1][j - 1].maxSum + tri[i][j].num;
}
}
}
}
 
maxFinal = tri[n - 1][0].maxSum;
for (int i = 1; i < n; i++) {
if (tri[n - 1][i].maxSum > maxFinal) {
maxFinal = tri[n - 1][i].maxSum;
}
}
 
printf("%d", maxFinal);

return 0;
}
}}}
= 아이디어 =
== 15이원준 ==
== 박인서 ==




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;
	int maxFinal;
	scanf("%d", &n);

	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= i; j++) {
			scanf("%d", &(tri[i][j].num));

			if (i == 0 && j == 0) {
				tri[i][j].maxSum = tri[i][j].num;
			}
			else {
				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 == 0 && i != 0) {
					tri[i][j].maxSum = tri[i - 1][j].maxSum + tri[i][j].num;
				}
				else if (j == i&&j != 0) {
					tri[i][j].maxSum = tri[i - 1][j - 1].maxSum + tri[i][j].num;
				}
			}
		}
	}

	maxFinal = tri[n - 1][0].maxSum;
	for (int i = 1; i < n; i++) {
		if (tri[n - 1][i].maxSum > maxFinal) {
			maxFinal = tri[n - 1][i].maxSum;
		}
	}

	printf("%d", maxFinal);

	return 0;
}

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.0228 sec