백준
-
백준 16935번 C++ 풀이백준 2018. 11. 18. 18:37
#include #include #include #include using namespace std; long long dp[31][31]; long long func(int n, int k){ if (dp[n][k] != -1){ return dp[n][k]; } if (k == 1){ dp[n][k] = 1; return dp[n][k]; } if (n == k){ dp[n][k] = 1; return dp[n][k]; } dp[n][k] = func(n-1, k) + func(n-1, k-1); return dp[n][k]; } int main(){ cin.tie(NULL); ios::sync_with_stdio(false); for (auto i =0; i n >> k; cout
-
백준 16936번 C++ 풀이백준 2018. 11. 18. 18:25
벡터로 담아 정렬한 뒤에 하나씩 갱신합니다. #include #include #include #include using namespace std; int buffer[1001]; bool isVisited[1001]; int main(){ cin.tie(NULL); ios::sync_with_stdio(false); int n; cin >> n; vector v; for (auto i=0; i> x >> y; v.push_back(make_pair(min(x,y),max(x,y))); } sort(v.begin(), v.end()); long long totalLength = 0; // bool shouldThinkPrevious = false; for (auto i=1; i
-
백준 1325번 C++ 풀이백준 2018. 11. 18. 17:08
최적화를 안 해서 메모리와 시간사용량이 대단합니다. #include #include #include #include using namespace std; vector buffer[10001]; bool isVisited[10001]; int maxHackable[10001]; int main(){ cin.tie(NULL); ios::sync_with_stdio(false); int n, m; cin >> n >> m; for (auto i=0; i> a >> b; // a가 b를 신뢰한다 -> b 해킹시 a buffer[b].push_back(a); } priority_queue pq; for (auto i=1; i
-
백준 14890번 C++ 풀이백준 2018. 11. 17. 19:33
#include #include #include #include #include #include using namespace std; int n; int buffer[101][101]; int l; int main(){ cin.tie(NULL); ios::sync_with_stdio(false); cin >> n >> l; for (auto x=0; x buffer[x][y]; } } int count = 0; for (auto x=0; x= l){ v[i].second -= l; }else { goto Fail; } } } } count++; Fail:; } } for (auto y=0; y= l){ v[i].second -= l; }else { goto Fail_2; } } } } count++; F..
-
백준 11725번 C++ 풀이백준 2018. 10. 9. 01:10
#include #include #include #define MAX 100001 using namespace std; vector adj[MAX]; bool isVisited[MAX] = {false}; int parent[MAX]; int n; int main() { cin.tie(NULL); ios::sync_with_stdio(false); cin >> n; for (auto i=1; i> a >> b; adj[a].push_back(b); adj[b].push_back(a); } queue q; q.push(1); while (!q.empty()){ int front = q.front(); q.pop(); isVisited[front] = true; int size = adj[front].siz..
-
백준 1300번 C++ 풀이백준 2018. 10. 7. 18:29
#include #include #define MAX 35002 using namespace std; queue q; //queue result; long long n; long long k; long long answer; void find(long long start, long long end) { if (start >= end) return; auto middle = (start + end) /2; auto cnt = 0; for (auto i=1; i= k){ answer = middle; find(start, middle); }else { find(middle+1, end); } } int main() { cin.tie(NULL); ios::sync_with_stdio(false); cin >>..