Skip to main content

Light OJ 1326 - Race

Problem No: 1326-Race

Both combinatorics and dynamic problem concept is used in this problem. We calculate how many ways the race can finish.
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define N 1000
  5. #define mod 10056
  6. ll ncr[+ 1][+ 1];
  7. ll dp[+ 1];
  8. int main()
  9. {
  10.     ll xx, yy;
  11.     int i, j;
  12.     ncr[0][0] = 1;
  13.     for (= 1; i <= N; i++) {
  14.         for (= 0; j <= N; j++) {
  15.             if (> i) ncr[i][j] = 0;
  16.             else if (== i || j == 0) ncr[i][j] = 1;
  17.             else ncr[i][j] = (ncr[- 1][- 1] + ncr[- 1][j]) % mod;
  18.         }
  19.     }
  20.     dp[0] = 1;
  21.     for (int i = 1; i <= N; i++) {
  22.         xx = 0;
  23.         for (int j = 1; j <= i; j++) {
  24.             yy = (ncr[i][j] * dp[- j]) % mod;
  25.             xx = (xx + yy) % mod;
  26.         }
  27.         dp[i] = xx;
  28.     }
  29.     int n, t, id = 0;
  30.     scanf ("%d"&t);
  31.     while (t--) {
  32.         scanf ("%d"&n);
  33.         ll ans = dp[n];
  34.         printf ("Case %d: %lld\n"++id, ans);
  35.     }
  36.     return 0;
  37. }

Comments

Popular posts from this blog

Resources for Programming Contest

Some important resources:                                           BAPS-BACS 1.CPPS                                                           7.Problem Solving Strategies 2.Beginner to Expert                                     8.An Awesome Blog for Programming 3.Bangla Resources                                      9.Ahnaf's Bangla Blog 4.Collection of Shakkhar                              10. Collection of UpsideDown ...

Interview Topics

Object-Oriented Programming  1. GeeksforGeeks                                         2.OPPs interview Java Concept 1. Basic Principles                                      2. Memory Management          3. Interview Questions                            4. SOLID 5. CppNuts                                                 6.Java Guides*** Networking 1. Java Socket                                           2.Kunal Kushwaha Layer, TCP, UDP Operating System   1.Farhan Hossan ...

Web Development

Basic for Front End and Backend 1.JavaScriptInfo                                                                         2.Sumit 3.Apna College***                                                                          4. W3School 5.Mosh