Ultraviolet A-12001 ultraviolet A panel discussion

Source: Internet
Author: User

Description


Ultraviolet A panel discussion

The ultraviolet online judge team is arranging a panel discussion for the next ACM-ICPC World Finals event in Orlando, Florida. they want that three or four of the contestants take part in the panel and as they have about 300 persons for selecting such a little group, they have decided to put some restrictions in order to reduce the number of possibilities.

After thinking about several options, they finally propose that in case the number of contestants to choice be 3, all of them must be of the same country or from three different countries; and in case the number be 4, at least three of them will be of the same country or must be from at least three different countries.

Cocould you help them to calculate the number of Different Selections they can make following the restrictions above.

Input

The input file contains several test cases; each of them consists of two lines.

The first contains two integersNAndMSeparated by one space.N(3N300) Is the number of contestants andM(1M50) The total number of different countries. The second line consistsNIntegers between 1 andM, Separated by a space, representing the country each contestant is from (it is not necessary that contestants will be fromMCountries ).

Last line of the input will contain in two zeroes and it won't be processed.

Output

For each input case write, in a line by itself, two integers separated by a space.

The first integer being be the number of ways to select a group of three people, and the second the number of ways to do it of four people.

Sample Input
 
3 55 4 25 33 1 3 2 210 101 8 9 1 6 7 3 4 10 40 0
Sample output
 
1 04 4104 209

Question: n teams, from M countries. Now three teams are provided: all three are from one country, or all three are from different countries; the four teams may be: at least three from different countries and at least three from the same country.

Idea: counting problem. First, it is better to calculate the three teams, both from one country or different, and pay attention to deduplication when all teams come from one country, the situations of the four teams are different from those of the four teams. The two teams are the same, the three teams are the same, and they are also important.

# Include <iostream> # include <cstdio> # include <cstring> # include <algorithm> typedef long ll; using namespace STD; const int maxn = 100; int n, m, num [maxn]; int main () {While (scanf ("% d", & N, & M )! = EOF & N + M) {memset (Num, 0, sizeof (Num); int A; For (INT I = 0; I <n; I ++) {scanf ("% d", & A); num [-- A] ++;} ll ans3 = 0; For (INT I = 0; I <m; I ++) {If (Num [I]> = 3) ans3 + = num [I] * (Num [I]-1) * (Num [I]-2) /6; For (Int J = I + 1; j <m; j ++) for (int K = J + 1; k <m; k ++) ans3 + = num [I] * num [J] * num [k];} ll sum = 0, ans4 = 0; For (INT I = 0; I <m; I ++) sum + = num [I]; for (INT I = 0; I <m; I ++) if (Num [I]> = 3) {ll TMP = num [I] * (Num [I]-1) * (Num [I]-2)/6; ans4 + = TMP * (Sum-num [I]); ans4 + = TMP * (Num [I]-3)/4;} For (INT I = 0; I <m; I ++) for (Int J = I + 1; j <m; j ++) for (int K = J + 1; k <m; k ++) {ans4 + = num [I] * (Num [I]-1)/2 * num [J] * num [k]; ans4 + = num [I] * num [J] * (Num [J]-1)/2 * num [k]; ans4 + = num [I] * num [J] * num [k] * (Num [k]-1)/2;} For (INT I = 0; I <m; I ++) for (Int J = I + 1; j <m; j ++) for (int K = J + 1; k <m; k ++) for (int l = k + 1; L <m; l ++) ans4 + = num [I] * num [J] * num [k] * num [l]; printf ("% LLD \ n", ans3, ans4 );} return 0 ;}


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.