본문 바로가기

분류 전체보기

[B10675] - Cow Routing https://www.acmicpc.net/problem/10675 그래프문제인 것처럼 보이지만 전혀 상관없고 그저 하나의 루틴에서 길이 있는지 확인하고해당하는 최소비용을 구하면 된다.1234567891011121314151617181920212223242526272829303132#include using namespace std;int main(){ int a, b, n; cin >> a >> b >> n; int ans = 1000000000; for (int i = 0; i > u >> v; int stage; int go = 0; for (int j = 0; j > stage; if (stage == a) go = 1; else if (go==1&&stage == b) go = 2; if (go.. 더보기
[B10752] - Cow Hopscotch https://www.acmicpc.net/problem/10752 재귀를 활용해서 이동시키면서 목적지에 도달하면 ans를 1씩 증가시키며경우의 수를 세어주면 됩니다.123456789101112131415161718192021222324252627282930#include using namespace std;char a[16][16];int r, c;int ans = 0;void move(int x, int y, char temp){ if (x == r - 1 && y == c - 1) { ans++; return; } for (int i = x + 1; i r >> c; for (int i = 0; i > a[i]; move(0, 0, a[0][0]); cout 더보기
[B10025] - 게으른 백곰 https://www.acmicpc.net/problem/10025 숫자범위를 잘 생각해서 구현하면 됩니다.123456789101112131415161718192021222324252627282930313233343536#include using namespace std;int a[1000001] = { 0, };int main(){ int n, k; cin >> n >> k; long long sum = 0; long long ans = 0; int length = 0; for (int i = 1; i > u >> v; a[v] = u; if (length 더보기
[B10656] - 십자말풀이 https://www.acmicpc.net/problem/10656조건맞춰서 구현하면 됩니다. 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162#include using namespace std;char a[51][51];void garocheck(int i,int j){ if (j == 0 || a[i][j - 1] == '#') { if ((a[i][j] == '.' || a[i][j] == '!') && (a[i][j+1] == '.' || a[i][j+1] == '!') && (a[i][j+2] == '.' || a[i][j+2] == '!'.. 더보기
[B9873] - Cow Baseball https://www.acmicpc.net/problem/9873조건에 맞게 간단한 구현문제입니다. 123456789101112131415161718192021222324252627282930313233343536#include #include #include using namespace std; int main(){ int n; cin >> n; vector a(n); int ans = 0; int max = 0; for (int i = 0; i > a[i]; } sort(a.begin(), a.end()); for (int i = 0; i 더보기
[B1520] - 내리막길 https://www.acmicpc.net/problem/1520 dfs에 메모이제이션을 통해 연산량을 줄여서 풀면 시간초과가 안납니다. 123456789101112131415161718192021222324252627282930313233343536373839404142#include using namespace std;int a[501][501];int d[501][501];int dx[] = { 0,0,1,-1 };int dy[] = { -1,1,0,0 };int m, n;int ans = 0;int dfs(int xnode, int ynode){ if (xnode == m - 1 && ynode == n - 1) { return 1; } if (d[xnode][ynode]!=-1) return d.. 더보기
[B9465] - 스티커 https://www.acmicpc.net/problem/9465 스티커입니다. 스티커를 최대한의 점수를 갖게 떼어내는 방법을 구하는 것이 목표입니다.최종답을 구할 때 이전 상태를 이용해야하기 때문에 dp로 풀 수 있습니다.어떤 위쪽 칸에 들어가는 최대값을 구하고 싶다면 그 전전칸의 위쪽의 최대값+전 칸의 아래쪽 값과 그 전 칸의 아래쪽 값 중 큰 값에 a[i][0]을 더해주면 됩니다.d[i][0]=max(d[i-2][0]+a[i-1][1],d[i][1])+a[i][0]으로 표현할 수 있네요그런데 이 값보다 전칸의 위쪽값이 더 크다면 어떨까요?즉 a[i][0]의 스티커를 떼어내지 않는 경우도 있을 수 있습니다.그러므로 d[i][0]=max(d[i-1][0],max(d[i-2][0]+a[i-1][1],d[.. 더보기
[B7562] - 나이트의 이동 https://www.acmicpc.net/problem/7562나이트는 가로로 2칸 세로로 1칸 혹은 가로로 1칸 세로로 2칸씩 이동합니다그에 따라 dx[], dy[]를 설정할 때 실수가 없으면 간단하게 풀 수 있는 BFS문제입니다 12345678910111213141516171819202122232425262728293031323334353637383940414243444546#include #include using namespace std;int dx[] = { 1,1,-1,-1,2,2,-2,-2 };int dy[] = { 2,-2,2,-2,1,-1,1,-1 };struct pos { int x; int y;};int main(){ int t; cin >> t; for (int zs = 1; zs.. 더보기
[S1952] - [모의 SW 역량테스트] 수영장 https://www.swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV5PpFQaAQMDFAUq&categoryId=AV5PpFQaAQMDFAUq&categoryType=CODE삼성 모의 테스트 수영장문제입니다.재귀함수를 잘 구현하면 됩니다. 12345678910111213141516171819202122232425262728293031323334353637383940414243444546#include using namespace std;int cost[4];int month[13] = { 0, };int ans;void money(int mon, int totalmoney){ if (mon > 12) { if (totalm.. 더보기
[B1208] - 부분집합의 합2 https://www.acmicpc.net/problem/1208부분집합의 합 1에 이어 2입니다이번엔 N이 40이 되었습니다.부분집합의 합 1처럼 모든 경우를 만든다면 틀리겠지만20개씩 나누어서 각각 부분집합으로 만들 수 있는 수를 배열로 만든 후sorting하여 합이 S가 되는 경우를 찾으면 됩니다. 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586#include #include #include using namespace std;int main(){ int n.. 더보기