목록Algorithm (55)
눈송이의 개발생활
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/mmcuS/btrpSknp1eG/ZmWS6rmYzROjikMxsXcu01/img.png)
문제 https://www.acmicpc.net/problem/17427 코드 #1 - WRONG❌ #약수의 합 구하는 함수 def f(x): global list sum=0 for i in range(1, x+1): if(x%i==0): list.append(i) for z in list: sum += z list = [] return sum list = [] totalSum =0 n = int(input()) for j in range(1, n+1): totalSum += f(j) print(totalSum) 풀이 #1 - WRONG❌ 처음에는 모든 약수를 구하고, 그 약수의 합을 또 구하는 방법으로 풀었었다. 예제5에서 시간이 조금 걸리기는 했지만 pypy로 하면 될거라고 생각하고 제출했는데 시간초..
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/0TStu/btrpPGjqbZq/bK6JMjxorW5nBc6lKQ5PbK/img.png)
문제 https://www.acmicpc.net/problem/13305 코드 #include #include using namespace std; long long km[100000]; long long pr[100000]; int main(){ cin.tie(0), cout.tie(0); ios_base::sync_with_stdio(0); long long total = 0; int n; cin >> n; for(int i=0; i> km[i]; } for(int i=0; i> pr[i]; } long long pr_now = pr[0]; for (int i=1; i pr[i]){ total += pr_now * km[i-1]; pr_now = pr[i]; } else{ total += pr_now..
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/zo8ZY/btrpP3S06q8/vAYYSDmIrLbnaEbU9Avhm1/img.png)
문제 https://www.acmicpc.net/problem/11047 코드 #include #include #include using namespace std; vector v; int main(){ cin.tie(0), cout.tie(0); ios_base::sync_with_stdio(0); int n, k, x; int count = 0; cin >> n >> k; for(int i=0; i> x ; v.push_back(x); } sort(v.begin(), v.end(), greater()); for(int i=0; i= 0){ k = k-v[i]; count++; } } cout
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/rOtfg/btrpTgRALTQ/r1hShxLu0m6p56ibeEkkrk/img.png)
문제 https://www.acmicpc.net/problem/11568 코드 #include #include using namespace std; int dp[1001]; int arr[1001]; int main(){ cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); int n; cin >> n; for(int i=0; i> arr[i]; dp[i]=1; } //LIS 사용 int result = 1; for(int i=0; i
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/bvMItk/btrpPFx0s9w/gxq5X2jaq8skbH6oKrl581/img.png)
문제 https://www.acmicpc.net/problem/11048 코드 #include #include using namespace std; int dp[1001][1001]; int arr[1001][1001]; int main(){ cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); int n, m; cin >> n >> m; for(int i=1; i arr[i][j]; } } for(int i=1; i
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/qDvSY/btrpP4qLQBS/AlHPDFLcdMMc74pXbDkjbk/img.png)
문제 https://www.acmicpc.net/problem/11726 코드 #include #include using namespace std; int dp[1001]; int main(){ cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); int n; cin >> n; dp[1]=1; dp[2]=2; for(int i=3; i
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/bRUod8/btrpMjIuV9G/I3oIM8J5ugZJktyfct9xR0/img.png)
문제 https://www.acmicpc.net/problem/9095 코드 #include #include using namespace std; int dp[10001]; int main(){ cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); int tc, n; dp[1]= 1; dp[2]=2; dp[3]=4; cin >> tc; for(int i=0; i> n; for (int i=4; i
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/YJh0L/btrpPFLA3EZ/ZtPMp5drBW1w1e7o8BWEl1/img.png)
문제 https://www.acmicpc.net/problem/2346 코드 #include #include using namespace std; typedef pair pairs; deque dq; int main(void){ cin.tie(0);cout.tie(0); ios_base::sync_with_stdio(false); int n; cin >> n; for(int i=0; i> x; dq.push_back(make_pair(i+1, x)); } while(!dq.empty()){ pairs poped = dq.front(); cout