2559. [NOIP2016] combination number problem, 2559noip2016

Source: Internet
Author: User

2559. [NOIP2016] combination number problem, 2559noip2016
[Description]

 

[Input format]


Read data from a file.

The first line has two integers, t and k. t represents the total number of test data sets in the test point. For the meaning of k, see [Problem description ].

Next, there are two integers n and m in each row in Line t. For the meanings of n and m, see [Problem description ].


[Output format]


Output to the file.

T rows. An integer in each row indicates the number of (I, j) pairs in all 0 <= I <= n, 0 <= j <= min (I, m) C (j, I) is a multiple of k.


[Example 1 input]
1 23 3
[Example 1 Output]
1
Tip]

In all possible cases, only C (1, 2) is a multiple of 2.

[Example 2 input]
2 54 56 7
[Example 2 output]
07
[Source]

NOIP2016 official data,

 

This question was awesome to me a few days ago.

But today we have learned a formula.

C, n + 1, m = C, n, m, n, m,

I just wanted to push it for a while. Later I pushed it to 55.

The value of % k is 90.

Later, I couldn't do it. I looked at the question of the great god. I could use the prefix and

So it seems that noip2016's question is not very difficult,

1 # include <iostream> 2 # include <cstdio> 3 # include <cstring> 4 # include <cmath> 5 using namespace std; 6 const int MAXN = 2001; 7 int T, k, n, m; 8 int dp [MAXN] [MAXN]; 9 int read (int & n) 10 {11 int flag = 0, x = 0; char c = '/'; 12 while (c <'0' | c> '9') {c = getchar (); if (c = '-') flag = 1;} 13 while (c> = '0' & c <= '9') x = x * 10 + (c-48), c = getchar (); 14 if (flag) n =-x; else n = x; 15} 16 int main () 17 {18 freopen ("problem. in "," r ", stdin); 19 freopen (" problem. out "," w ", stdout); 20 read (T); read (k); 21 for (int I = 0; I <= 2001; I ++) 22 dp [I] [0] = 1, dp [I] [I] = 1; 23 for (int I = 0; I <= 2001; I ++) 24 for (int j = 0; j <= 2001; j ++) 25 if (dp [I + 1] [j] = 0) 26 dp [I + 1] [j] = (dp [I] [j] + dp [I] [J-1]); 27 28 while (T --) 29 {30 read (n); read (m); 31 int ans = 0; 32 for (int I = 1; I <= n; I ++) 33 for (int j = 1; j <= min (I, m); j ++) 34 if (dp [I] [j] % k = 0) 35 ans ++; 36 printf ("% d \ n", ans); 37} 38 return 0; 39}55 1 # include <iostream> 2 # include <cstdio> 3 # include <cstring> 4 # include <cmath> 5 # define LL long 6 using namespace std; 7 const int MAXN = 2003; 8 int T, k, n, m; 9 LL dp [MAXN] [MAXN]; 10 LL sum [MAXN] [MAXN]; 11 int read (int & n) 12 {13 int flag = 0, x = 0; char c = '/'; 14 while (c <'0' | c> '9') {c = getchar (); if (c = '-') flag = 1 ;} 15 while (c> = '0' & c <= '9') x = x * 10 + (c-48), c = getchar (); 16 if (flag) n =-x; else n = x; 17} 18 int main () 19 {20 freopen ("problem. in "," r ", stdin); 21 freopen (" problem. out "," w ", stdout); 22 23 read (T); read (k); 24 for (int I = 1; I <= 2002; I ++) 25 dp [I] [I] = 1, dp [I] [1] = I % k; 26 for (int I = 0; I <= 2002; I ++) 27 for (int j = 2; j <I; j ++) 28 dp [I] [j] = (dp [I-1] [j] % k + dp [I-1] [J-1] % k) % k; 29 30/* for (int l = 0; l <= 50; l ++) 31 for (int j = 0; j <= l; j ++) 32 cout <dp [l] [j]; 33 cout <endl; */34 // cout <dp [1] [2]; 35 36 for (int I = 1; I <= 2002; I ++) 37 for (int j = 1; j <= I; j ++) 38 {39 if (dp [I] [j] = 0) sum [I] [j] = sum [I] [J-1] + 1; // meet condition 40 else sum [I] [j] = sum [I] [J-1]; 41} 42 43 while (T --) 44 {45 read (n ); read (m); 46 LL ans = 0; 47 for (int I = 1; I <= n; I ++) 48 ans + = sum [I] [min (I, m)]; 49 cout <ans <endl; 50 // printf ("% d \ n ", sum [n] [min (n, m)]); 51} 52 return 0; 53}AC

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.