JXNVCE ALGO-LOG YouJin Jung

BOJ-2750

  1. Iterate from the beginning
bool canJump(vector<int>& nums) {
    int pivot = nums[0];
    bool result = true;
    if (nums.size() == 1) return true;
    if (nums[0] == 0) return false;
    for (int i = 1; i < nums.size(); i++) {
        pivot--;
        if (nums[i] >= pivot) pivot = nums[i];
        if (nums[i] == 0 && pivot == 0 && i != nums.size() - 1) {
            result = false;
            break;
        }
    }
    return result;
}
  1. Iterate from the back (my solution) Sum up the element’s index and element value to determine if it satisifies the condition
bool canJump(vector<int>& nums) {
    int last_index = nums.size() - 1;
    if (nums.size() == 1) return true;
    for (int i = nums.size() - 1; i >= 0; --i)
        if (i + nums[i] >= last_index) last_index = i;
    if (last_index == 0) return true;
    else return false;
}

csh vs bash

Shell의 역할

Shells offer a standard way of extending the command line environment. You can swap out the default shell for another one, if you like.

Unix, Linux OS가 가진 shell

  • C Shell
  • Bourne Shell
  • Bourne Again Shell (BASH)

CSH

  • 1970년대 후반 Bill Joy에 의해 개발됨
  • Bourne Shell 호환 안됨
  • CSH에서만 작동하는
    • /etc/.login, /etc/csh.cshrc, /etc/csh.login, ~/.cshrc, ~/.login

BASH

  • 1980년대 후반 Brian Fox에 의해 개발됨
  • Bourne Shell 호환됨
  • BASH에서만 작동하는
    • $ENV (typically ~/.kshrc), /etc/profile, ~/.profile, ~/.bash_profile, ~/.bash_login, ~/.bash_logout, ~/.bashrc.

GFG NEXT GREATER ELEMENT

#include<iostream>

using namespace std;

void printNGE(int arr[], int n) {
    int next, i, j;
    for (i = 0; i < n; i++) {
        next = -1;
        for (j = i + 1; j < n; j++) {
            if (arr[i] < arr[j]) {
                next = arr[j];
                break;
            }
        }
        cout << arr[i] << " -- " << next << endl;
    }
}
 
int main() {
    int arr[] = {11, 13, 21, 3};
    int n = sizeof(arr)/sizeof(arr[0]);
    printNGE(arr, n);
    return 0;
}

GFG ENTRINGER NUMBER (RECURSIVE)

#include <bits/stdc++.h>

using namespace std;

int zigzag(int n, int k) {

	if (n == 0 && k == 0)
		return 1;

	if (k == 0)
		return 0;

	return zigzag(n, k - 1) +	zigzag(n - 1, n - k);
}

int main() {
	int n = 4, k = 3;
	cout << zigzag(n, k) << endl;
	return 0;
}

GFG DELANNOY NUMBER (DYNAMIC PROGRAMMING)

#include <bits/stdc++.h>

using namespace std;

int dealnnoy(int n, int m) {
	int dp[m + 1][n + 1];

	for (int i = 0; i <= m; i++)
		dp[i][0] = 1;
	for (int i = 0; i <= m; i++)
		dp[0][i] = 1;

	for (int i = 1; i <= m; i++)
		for (int j = 1; j <= n; j++)
			dp[i][j] = dp[i - 1][j] + dp[i - 1][j - 1] + dp[i][j - 1];

	return dp[m][n];
}

int main() {
	int n = 3, m = 4;
	cout << dealnnoy(n, m) << endl;
	return 0;
}