Skip to main content

Light OJ - 1095

Problem No: 1095 - Arrange the Numbers

This problem has two parts. This is a typical combinatorics problem.


  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define mod 1000000007
  5. #define N 1000
  6. ll ncr[+ 2][+ 2];
  7. ll fact[+ 2];
  8. int main()
  9. {
  10.     ncr[0][0] = 1;
  11.     for (int i = 1; i <= N; i++) {
  12.         for (int j = 0; j <= N; j++) {
  13.             if (> i) ncr[i][j] = 0;
  14.             else if (== 0 || i == j) ncr[i][j] = 1;
  15.             else ncr[i][j] = (ncr[- 1][- 1] + ncr[- 1][j]) % mod;
  16.         }
  17.     }
  18.     fact[0] = 1;
  19.     for (ll i = 1; i <= N; i++) {
  20.         fact[i] = (* fact[- 1]) % mod;
  21.     }
  22.     int t, n, m, k, id = 0, nn, mm;
  23.     ll ans, xx;
  24.     scanf ("%d"&t);
  25.     while (t--) {
  26.         scanf ("%d %d %d"&n, &m, &k);
  27.         ans = fact[- k];
  28.         nn = m - k;
  29.         mm = n - k;
  30.         for (int i = 1; i <= nn; i++) {
  31.             xx = (ncr[nn][i] * fact[mm - i]) % mod;
  32.             if (& 1) ans = (ans - xx + mod) % mod;
  33.             else ans = (ans + xx + mod) % mod;
  34.         }
  35.         ans = (ans * ncr[m][k]) % mod;
  36.         printf ("Case %d: %lld\n"++id, ans);
  37.     }
  38.     return 0;
  39. }

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