Google Round B APAC Test

Source: Internet
Author: User

A: The password is composed of n different characters and m length. How many cases are there?

Solution: the equation of state transition is DP [I] [J] = DP [I-1] [J] * j + dp [I-1] [J-1] * (N-J + 1 );

Solution code:

1 // file name:. CPP 2 // Author: darkdream 3 // created time: monday, September 15, 2014, 39 seconds, 4 5 # include <vector> 6 # include <list> 7 # include <map> 8 # include <set> 9 # include <deque> 10 # include <stack> 11 # include <bitset> 12 # include <algorithm> 13 # include <functional> 14 # include <numeric> 15 # include <utility> 16 # include <sstream> 17 # include <iostream> 18 # include <iomanip> 19 # include <cstdio> 20 # include <cmath> 21 # include <cstdlib> 22 # include <cstring> 23 # include <ctime> 24 # define ll long long25 26 using namespace STD; 27 ll DP [200] [200]; 28 # define M 100000000729 int main () {30 freopen ("out", "W", stdout); 31 int T; 32 scanf ("% d", & T); 33 for (int ca = 1; Ca <= T; CA ++) 34 {35 int n, m; 36 scanf ("% d", & N, & M); 37 memset (DP, 0, sizeof (DP )); 38 DP [1] [1] = N; 39 for (INT I = 2; I <= m; I ++) 40 {41 for (Int J = 1; j <= N; j ++) 42 DP [I] [J] = (DP [I-1] [J] * j) % m + dp [I-1] [J-1] * (N-J + 1) % m; 43} 44 printf ("case # % d: % LLD \ n", CA, DP [m] [N] % m); 45} 46 Return 0; 47}
View code

 

Google Round B APAC Test

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.