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[N + 1][N + 1];
  7. ll dp[N + 1];
  8. int main()
  9. {
  10.     ll xx, yy;
  11.     int i, j;
  12.     ncr[0][0] = 1;
  13.     for (i = 1; i <= N; i++) {
  14.         for (j = 0; j <= N; j++) {
  15.             if (j > i) ncr[i][j] = 0;
  16.             else if (j == i || j == 0) ncr[i][j] = 1;
  17.             else ncr[i][j] = (ncr[i - 1][j - 1] + ncr[i - 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[i - 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

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 ...

MapReduce

  Video Tutorial 1.Arnob Chakrabarty                                                 3. An example of MapReduce 2.Online Learning Center                                        4.A fine example of MapReduce 5. Jar File                                                                     6. Word Count Blog 1. Hadoop MapReduce                                             2.Onesmus Mbaabu 3.Big Data Hadoop

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 ...