๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

Algorithm ๐Ÿง‘๐Ÿป‍๐Ÿ’ป/CodeUp11

1485 : 2์ฐจ์› ๋ฐฐ์—ด ๋‹ฌํŒฝ์ด(2) ๋ฌธ์ œ [๊ธฐ์ดˆ-๋ฐฐ์—ด์—ฐ์Šต] 2์ฐจ์› ๋ฐฐ์—ด ๋‹ฌํŒฝ์ด ์ฑ„์šฐ๊ธฐ 4-2 ๋‹ค์Œ๊ณผ ๊ฐ™์€ n*m ๋ฐฐ์—ด ๊ตฌ์กฐ๋ฅผ ์ถœ๋ ฅํ•ด๋ณด์ž. ์ž…๋ ฅ์ด 3 4์ธ ๊ฒฝ์šฐ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ถœ๋ ฅํ•œ๋‹ค. 12 11 10 9 3 2 1 8 4 5 6 7 ์ž…๋ ฅ์ด 4 5์ธ ๊ฒฝ์šฐ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ถœ๋ ฅํ•œ๋‹ค. 20 19 18 17 16 7 6 5 4 15 8 1 2 3 14 9 10 11 12 13 ์ž…๋ ฅ์ด codeup.kr ์ฝ”๋“œ #include using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); int n,m; cin>>n>>m; int left_right_cnt = m, up_down_cnt = n-1; int arr[101][101] = {0, }; int num = n*m; in.. 2022. 3. 14.
1484 : 2์ฐจ์› ๋ฐฐ์—ด ๋‹ฌํŒฝ์ด(1) ๋ฌธ์ œ [๊ธฐ์ดˆ-๋ฐฐ์—ด์—ฐ์Šต] 2์ฐจ์› ๋ฐฐ์—ด ๋‹ฌํŒฝ์ด ์ฑ„์šฐ๊ธฐ 4-1 ๋‹ค์Œ๊ณผ ๊ฐ™์€ n*m ๋ฐฐ์—ด ๊ตฌ์กฐ๋ฅผ ์ถœ๋ ฅํ•ด๋ณด์ž. ์ž…๋ ฅ์ด 3 4์ธ ๊ฒฝ์šฐ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ถœ๋ ฅํ•œ๋‹ค. 1 2 3 4 10 11 12 5 9 8 7 6 ์ž…๋ ฅ์ด 4 5์ธ ๊ฒฝ์šฐ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ถœ๋ ฅํ•œ๋‹ค. 1 2 3 4 5 14 15 16 17 6 13 20 19 18 7 12 11 10 9 8 ์ž…๋ ฅ์ด codeup.kr ์ฝ”๋“œ #include using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); int N,M; cin>>N>>M; int num = 1; int loop = N*M; int arr[101][101] = {0,}; int x = 0, y = 0; int right_left.. 2022. 3. 14.
3510 : ์˜ˆ์‚ฐ ๊ด€๋ฆฌ ๋ฌธ์ œ ์˜ˆ์‚ฐ ๊ด€๋ฆฌ ์ฒซ์งธ ์ค„์— ๋‚จ์€ ์˜ˆ์‚ฐ(B)๊ฐ€ ์ž…๋ ฅ๋œ๋‹ค. ( 10 >N; for(int i=0; i>inp; v.push_back(inp); } sort(v.begin(),v.end(),greater()); for(int i=0; i 2022. 1. 16.
3701 : ํŒŒ์Šค์นผ ์‚ผ๊ฐํ˜• ๋ฌธ์ œ ํŒŒ์Šค์นผ ์‚ผ๊ฐํ˜• ๋ฐฐ์—ด์˜ ๊ฐ’์ด ์ปค์ง€๋ฏ€๋กœ ๋ฐฐ์—ด์€ long long ์œผ๋กœ ์„ ์–ธํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. nCr์˜ ์ ํ™”์‹์˜ ์›๋ฆฌ๋„ ์ด ์‚ผ๊ฐํ˜•์˜ ์›๋ฆฌ์™€ ๋˜‘๊ฐ™์Šต๋‹ˆ๋‹ค. nCr = n-1Cr + n-1Cr-1 codeup.kr ์ฝ”๋“œ #include using namespace std; long long dp[51][51]; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); int n; cin>>n; for(int i=0; i 2022. 1. 16.
1510 : ํ™€์ˆ˜ ๋งˆ๋ฐฉ์ง„ ๋ฌธ์ œ ํ™€์ˆ˜ ๋งˆ๋ฐฉ์ง„ ๋งˆ๋ฐฉ์ง„(magic square)์ด๋ž€ ๊ฐ€๋กœ, ์„ธ๋กœ, ๋Œ€๊ฐ์„ ์˜ ํ•ฉ์ด ๊ฐ™์€ ์‚ฌ๊ฐํ˜•์„ ๋งํ•œ๋‹ค. ํ™€์ˆ˜ n์„ ์ž…๋ ฅ์œผ๋กœ ๋ฐ›์•„ n*n ํ™€์ˆ˜ ๋งˆ๋ฐฉ์ง„์„ ๋งŒ๋“ค์–ด ๋ณด์ž. ๋งŒ๋“œ๋Š” ๋ฐฉ๋ฒ•์€ ์—ฌ๋Ÿฌ๊ฐ€์ง€ ๋ฐฉ๋ฒ•์ด ์žˆ์ง€๋งŒ, ์•„๋ž˜์™€ ๊ฐ™์€ ๋ฐฉ๋ฒ•์„ ์ด codeup.kr ์ฝ”๋“œ #include #include using namespace std; int arr[51][51]; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); int n; cin>>n; arr[0][n/2]=1; //1. ์‹œ์ž‘์€ ์ฒซํ–‰, ํ•œ ๊ฐ€์šด๋ฐ ์—ด์— 1์„ ๋‘”๋‹ค. int row=0,col=n/2; bool flag = false; for(int i=2; i 2022. 1. 16.
4503 : ๋ฐ”์ด๋Ÿฌ์Šค ๋ฌธ์ œ ๋ฐ”์ด๋Ÿฌ์Šค 1๋ฒˆ ์ปดํ“จํ„ฐ๊ฐ€ ์›œ ๋ฐ”์ด๋Ÿฌ์Šค์— ๊ฑธ๋ ธ์„ ๋•Œ, 1๋ฒˆ ์ปดํ“จํ„ฐ๋ฅผ ํ†ตํ•ด ์›œ ๋ฐ”์ด๋Ÿฌ์Šค์— ๊ฑธ๋ฆฌ๊ฒŒ ๋˜๋Š” ์ปดํ“จํ„ฐ์˜ ์ˆ˜๋ฅผ ์ฒซ์งธ ์ค„์— ์ถœ๋ ฅํ•œ๋‹ค. codeup.kr ์ฝ”๋“œ #include #include using namespace std; int N,M,ans; int visited[101]; vectorv[101]; void dfs(int start){ visited[start]=1; ans++; for(int i=0; i>N>>M; for(int i=0; i>a>>b; v[a].push_back(b); v[b].push_back(a); } dfs(1); cout 2022. 1. 14.
3705 : ์—ฐ์†๋œ ๊ตฌ๊ฐ„์˜ ์ตœ๋Œ€ํ•ฉ ๋ฌธ์ œ ์—ฐ์†๋œ ๊ตฌ๊ฐ„์˜ ์ตœ๋Œ€ํ•ฉ ์ฒซ์งธ์ค„์— ์ˆ˜์—ด์˜ ์›์†Œ์˜ ๊ฐœ์ˆ˜ n์ด ์ž…๋ ฅ๋œ๋‹ค. (1 N; for(int i=0; i>arr[i]; } int ans=arr[0]; dp[0]=arr[0]; for(int i=1;i 2022. 1. 14.
3108 : ์ •์˜ฌ ์ฐธ์—ฌ ํ•™์ƒ ๋ฆฌ์ŠคํŠธ ๋งŒ๋“ค๊ธฐ 1 ๋ฌธ์ œ ์ •์˜ฌ ์ฐธ์—ฌ ํ•™์ƒ ๋ฆฌ์ŠคํŠธ ๋งŒ๋“ค๊ธฐ 1 10 I 1011 ํ•œ๋ผ์‚ฐ I 999 ๋ฐฑ๋‘์‚ฐ I 999 ์˜ค๋Œ€์‚ฐ D 999 ๋ฐฑ๋‘์‚ฐ I 800 ๋ฐฑ๋‘์‚ฐ D 500 ํ•œ๋ผ์‚ฐ I 900 ๋‚จ์‚ฐ I 950 ๊ธˆ๊ฐ•์‚ฐ I 1205 ์ง€๋ฆฌ์‚ฐ I 700 ๋ถํ•œ์‚ฐ 1 2 4 5 6 codeup.kr ์ฝ”๋“œ #include #include #include #include using namespace std; int N; struct Data{ int number; string name; }; bool cmp(const Data &v1, const Data &v2){ return v1.number>N; vectorv; for(int i=0; i>cmd>>number>>name; if(cmd=='I'){ if(check[number]==0){ che.. 2022. 1. 14.
2641 : ์ˆ๋‹ค๋ฆฌ์˜ ๊ณ„๋‹จ ์˜ค๋ฅด๊ธฐ (Small) ๋ฌธ์ œ ์ˆ๋‹ค๋ฆฌ์˜ ๊ณ„๋‹จ ์˜ค๋ฅด๊ธฐ (Small) * 4๊ฐœ์˜ ๊ณ„๋‹จ์„ ์˜ค๋ฅด๋Š” ๋ฐฉ๋ฒ•์€ - 1 1 1 1 - 1 1 2 - 1 2 1 - 2 1 1 - 2 2 - 1 3 - 3 1 codeup.kr ์ฝ”๋“œ #include using namespace std; int dp[16]; int N,ans; void dfs(int current,int before_step,int before_before_step){ if(current==N){ ans++; return; } else if(current>N) return; else{ if(before_step==3||before_before_step==3){ dfs(current+1,1,before_step); dfs(current+2,2,before_step); } else{ .. 2022. 1. 14.