λ³Έλ¬Έ λ°”λ‘œκ°€κΈ°
🐍 Algorithm/μ•Œκ³ λ¦¬μ¦˜-Python

[μ•Œκ³ λ¦¬μ¦˜] Day2 - 2775번 λΆ€λ…€νšŒμž₯이 λ ν…Œμ•Ό

by Danna 2018. 8. 4.
728x90
728x90

01 문제

02 μ•Œκ³ λ¦¬μ¦˜
  • 0μΈ΅, 1μΈ΅, 2μΈ΅ … 에 λŒ€ν•΄ κ·œμΉ™μ„ μ°Ύμ•˜λ‹€.
  • 0측은 i호 일 λ•Œ, iλͺ…이 μ‚΄κΈ° λ•Œλ¬Έμ— λ”°λ‘œ 값을 λ„£μ–΄μ£Όμ—ˆκ³ 
  • 1μΈ΅ μ΄ν›„λΆ€ν„°λŠ” ν˜„μž¬ μΈ΅ - 1측의 인원을 반볡문으둜 κ³„μ‚°ν•΄μ„œ 값을 λ„£μ–΄μ£Όμ—ˆλ‹€.

03 μ½”λ“œ

#include "stdafx.h"
 
int main(void)
{
       int i, j, jj;
       int T, k, n;
       int residents[15][15] = { 0, };
 
       // Test case T
       scanf_s("%d", &T);
 
       while (T>0)
       {
               // 1 2 3
               // 1 3 6
               // 1 4 10
               printf("# Test case %d\n", T);
               scanf_s("%d", &k);
               scanf_s("%d", &n);
 
               // init zero floor
               printf("0 μΈ΅ : ");
               for (j = 0; j < n; j++)
               {
                      residents[0][j] = j + 1;
                      printf("%d ", residents[0][j]);
               }
               printf("\n");
 
               for (i = 1; i <= k; i++)
               {
                      printf("%d μΈ΅ : ", i);
                      for (j = 0; j<n; j++)
                      {
                              int sum_residents = 0;
 
                              for (jj = 0; jj <= j; jj++)
                                     sum_residents += residents[i-1][jj];
 
                              residents[i][j] = sum_residents;
 
                              printf("%d ", residents[i][j]);
                      }
                      printf("\n");
               }
 
               printf("%d\n", residents[k][n - 1]);
               T--;
       }
 
       return 0;
}


728x90
728x90