본문 바로가기

Algorithm

(33)
[Hacker Rank] BASIC JOIN - 1 👻 QUESTIONGiven the CITY and COUNTRY tables, query the sum of the populations of all cities where the CONTINENT is 'Asia'. Note: CITY.CountryCode and COUNTRY.Code are matching key columns. 🚀ANSWERSELECT SUM(CITY.POPULATION)FROM CITYJOIN COUNTRY ON CITY.COUNTRYCODE = COUNTRY.CODEWHERE COUNTRY.CONTINENT = 'Asia'; 👻 QUESTIONGiven the CITY and COUNTRY tables, query the names of all cities where ..
[Hacker Rank] BASIC SELECT - 2 👻 QUESTIONQuery the list of CITY names starting with vowels (i.e., a, e, i, o, or u) from STATION. Your result cannot contain duplicates. 🚀ANSWERSELECT DISTINCT CITYFROM STATIONWHERE LEFT(LOWER(CITY), 1) IN ('a', 'e', 'i', 'o', 'u'); 🔮 TIPSThe LEFT() function extracts a number of characters from a string (starting from left).LEFT(string, number_of_chars) 👻 QUESTIONQuery the list of CITY na..
[Hacker Rank] BASIC SELECT - 1 👻 QUESTIONQuery all columns for all American cities in the CITY table with populations larger than 100000. The CountryCode for America is USA. 🚀ANSWERSELECT * FROM CITYWHERE COUNTRYCODE='USA' AND POPULATION > 100000; 👻 QUESTIONQuery the NAME field for all American cities in the CITY table with populations larger than 120000. The CountryCode for America is USA. 🚀ANSWERSELECT NAME FROM CITYWH..
[Algorithm|Python] 백준 1351번 from collections import defaultdictimport sysinput = sys.stdin.readlinedef dfs(n): if data[n] != 0: return data[n] data[n] = dfs(n // p) + dfs(n // q) return data[n]if __name__ == "__main__": n, p, q = map(int, input().split()) data = defaultdict(int) data[0] = 1 print(dfs(n))
[Algorithm|Python] 백준 2225번 import sysinput = sys.stdin.readlinen, k = map(int,input().split())dp = [[0] * 201 for _ in range(201)]for i in range(201): dp[1][i] = 1 dp[2][i] = i+1for i in range(3, 201): dp[i][1] = i for j in range(2, 201): dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % 1000000000print(dp[k][n])
[Algorithm|Python] 백준 9251번 s1 = list(input())s2 = list(input())lcs = [[0] * (len(s2) + 1) for _ in range(len(s1) + 1)]for i in range(1, len(s1)+1): for j in range(1, len(s2)+1): if s1[i-1] == s2[j-1]: lcs[i][j] = lcs[i-1][j-1] + 1 else: lcs[i][j] = max(lcs[i-1][j], lcs[i][j-1]) print(max(map(max,lcs)))
[Algorithm|Python] 백준 11053번 import sysinput = sys.stdin.readline N = int(input()) A = list(map(int, input().split()))dp = [1] * N for i in range(1, N): for j in range(i): if A[i] > A[j]: dp[i] = max(dp[i], dp[j]+1) print(max(dp))
[Python|Algorithm] 백준 1003번 파이썬 T = int(input())for _ in range(T): N = int(input()) a, b = 1, 0 for i in range(N): a,b = b, a+b print(a,b)