-
Notifications
You must be signed in to change notification settings - Fork 0
9주차 알고리즘 문제 풀이 - 황희정 #36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| #include<iostream> | ||
| #include<vector> | ||
| using namespace std; | ||
|
|
||
| int arr[40]; | ||
| int zero = 0, one = 0; | ||
| int fibonacci(int n) { | ||
| if (n == 0) { | ||
| zero = zero + 1; | ||
| return 0; | ||
| } | ||
| else if (n == 1) { | ||
| one = one + 1; | ||
| return 1; | ||
| } | ||
| else { | ||
| int x = n - 1; | ||
| int y = n - 2; | ||
| return fibonacci(x) + fibonacci(y); | ||
| } | ||
| } | ||
|
|
||
| int main() { | ||
| int t; | ||
| cin >> t; | ||
| vector<pair<int, int>> result; | ||
| result.push_back({ 1,0 }); //0 ���� | ||
| result.push_back({ 0,1 });//1 ���� | ||
| for (int i = 0;i < t;i++) { | ||
| cin >> arr[i]; | ||
|
|
||
| } | ||
|
|
||
| for (int i = 0;i < t;i++) { | ||
| if(arr[i]>result.size()-1) { | ||
| for (int j = result.size();j <= arr[i];j++) { | ||
| result.push_back({ result[j - 1].first + result[j - 2].first,result[j - 1].second + result[j - 2].second }); | ||
| } | ||
| } | ||
|
|
||
| cout << result[arr[i]].first<<" "<<result[arr[i]].second << "\n"; | ||
|
|
||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| #include<iostream> | ||
| #include<vector> | ||
| using namespace std; | ||
|
|
||
| int maxfun(int a, int b) { | ||
| if (a > b) | ||
| return a; | ||
|
|
||
| else | ||
| return b; | ||
| } | ||
|
|
||
| int main() { | ||
| int c; | ||
| cin >> c; | ||
| vector<int> vec; | ||
| for (int i = 0;i < c;i++) { | ||
| int t; | ||
| cin >> t; | ||
| vec.push_back(t); | ||
| } | ||
| int max = -1000; | ||
| int sum = 0; | ||
|
|
||
| for (int i = 0;i < c;i++) { | ||
| if (vec[i] > sum + vec[i]) { | ||
| sum = vec[i]; | ||
| max = maxfun(sum, max); | ||
| } | ||
| else { | ||
| sum += vec[i]; | ||
| max = maxfun(sum, max); | ||
| } | ||
| } | ||
| cout << max <<"\n"; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| package _1932; | ||
|
|
||
| import java.io.*; | ||
| import java.sql.Array; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 문제 풀이에 사용 되지 않은 코드로 삭제가 필요해 보여요.. 🥹
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| import java.util.*; | ||
|
|
||
| public class Main { | ||
| public static void main(String[] args) throws IOException { | ||
| BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
| StringBuilder sb = new StringBuilder(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 문제 풀이에 사용 되지 않은 코드로 삭제가 필요해 보여요.. 🥹
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| int n = Integer.parseInt(br.readLine()); | ||
| int [][] arr = new int[n][n]; | ||
| StringTokenizer st; | ||
| for(int i=0;i<n;i++){ | ||
| st = new StringTokenizer(br.readLine()); | ||
| for(int j=0;j<=i;j++){ | ||
| arr[i][j] = Integer.parseInt(st.nextToken()); | ||
| } | ||
| } | ||
|
Comment on lines
+12
to
+20
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저는 아래의 코드는 제가 사용하는 방법인데 스타일에 따라 참고 해보셔도 좋을 것 같습니다! (코드가 틀렸다는 것은 아니에요!) int n = Integer.parseInt(br.readLine()); // Input Line 1
int[][] arr = new int[n][n];
for (int i = 0; i < n; i++) { // n번 반복
arr[i] = Arrays.stream(br.readLine().split(" ")) // 1) Input을 통해 공백(" ")을 기준으로 나누기
.mapToInt(Integer::parseInt) // 2) 나눈 값을 Integer 타입으로 매핑(String -> Integer)
.toArray(); // 배열로 만들기
} |
||
| int result[][] = new int[n][n]; | ||
| result[0][0] = arr[0][0]; | ||
| int max=arr[0][0]; | ||
| for(int i=1;i<n;i++){ | ||
| for(int j=0;j<=i;j++) { | ||
| if (j == 0) { | ||
| result[i][j] = result[i-1][j]+arr[i][j]; | ||
| } else if(j==i){ | ||
| result[i][j] = result[i-1][j-1]+arr[i][j]; | ||
| } else{ | ||
| result[i][j] = Math.max(result[i - 1][j] + arr[i][j],result[i-1][j-1]+arr[i][j] ); | ||
|
|
||
|
|
||
| if(max<result[i][j]){ | ||
| max = result[i][j]; | ||
| } | ||
| } | ||
|
|
||
| } | ||
|
Comment on lines
+24
to
+39
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 코드를 한번 점검해 볼 필요가 있을 것 같아요!(띄워쓰기, 코드 다음 라인 줄 맞춤..) for (int i = 1; i < n; i++) {
for (int j = 0; j <= i; j++) {
if (j == 0) {
result[i][j] = result[i - 1][j] + arr[i][j];
} else if (j == i) {
result[i][j] = result[i - 1][j - 1] + arr[i][j];
} else {
result[i][j] = Math.max(result[i - 1][j] + arr[i][j], result[i - 1][j - 1] + arr[i][j]);
}
max = Math.max(max, result[i][j]);
}
}
|
||
|
|
||
| System.out.println(max); | ||
|
|
||
|
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| #include<iostream> | ||
| using namespace std; | ||
| int main() { | ||
| long long arr[91][2] = { {0,0},{0,1},{1,0} }; | ||
|
|
||
| int n; | ||
| cin >> n; | ||
|
|
||
| int sum = 0; | ||
| for (int i = 2; i <= n; i++) | ||
| { | ||
| arr[i][0] = arr[i - 1][0] + arr[i - 1][1]; | ||
| arr[i][1] = arr[i - 1][0]; | ||
|
|
||
|
|
||
|
|
||
|
|
||
| } | ||
| cout << arr[n][0] + arr[n][1] << "\n"; | ||
| return 0; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
패키지 경로가 이상한데 한번 확인이 필요해 보여요!
package heejung.boj.DP._1932;가 되어야 해요!