Zoj 3644 Kitty's game (DP)

Source: Internet
Author: User

Description

Kitty is a little cat. She is crazy about a game recently.

There areNScenes in the game (mark from 1N). Each scene has a numberPi. Kitty's score will become least_common_multiple (X,Pi) When Kitty enterITh scene.XIs the score that Kitty had previous. Notice that kitty will become mad if she go to another scene but the score didn't change.

Kitty is staying in the first scene now (P1 score). Please find out how many paths which can arrive atNTh scene and hasKScores at there. Of course, you can't make Kitty mad.

We regard two paths different if and only if the edge sequence is different.

Input

There are multiple test cases. For each test case:

The first line contains three integerN(2 ≤N≤ 2000 ),M(2 ≤M≤ 20000 ),K(2 ≤K≤ 106). Then followedMLines. Each line contains two integerU,V(1 ≤U,V≤N, u =v) indicate we can goVTh scene fromUTh scene directly. The last line of each case contains N integerPI (1 ≤P(I ≤ 106 ).

Process to the end of input.

Output

One line for each case. The number of paths module 1000000007.

Sample Input

5 6 841 22 51 33 51 44 51 5 4 12 21

Sample output

2
 
Madan and map are not very useful.
Question: N points M: m channels K: value, each point has a value, requiring different solutions from the start point to the end point. No need to change LCM in the middle
 
# Include <iostream> # include <cstdio> # include <cstring> # include <algorithm> # include <vector> # include <map> typedef long ll; using namespace STD; # define repf (I, a, B) for (INT I = A; I <= B; ++ I) # define rep (I, n) for (INT I = 0; I <n; ++ I) # define clear (A, x) memset (A, X, sizeof A) const int maxn = 2010; const int mod = 1e9 + 7; vector <ll> V [maxn]; Map <LL, ll> m; ll DP [maxn] [maxn], p [maxn], k; I NT n, m; ll gcd (ll a, LL B) {return B? Gcd (B, A % B): A;} ll lcm (ll a, LL B) {return a/gcd (a, B) * B ;} ll DFS (ll u, ll s) {// cout <"Madan" <u <Endl; int num = m [s]; if (DP [u] [num]) return DP [u] [num]; ll ret = 0; For (INT I = 0; I <(INT) V [u]. size (); I ++) {ll ED = V [u] [I]; ll LCM = lcm (S, P [ed]); if (K % LCM | LCM = S & U! = 0) continue; RET + = DFS (ED, LCM) % MOD;} return DP [u] [num] = ret;} int main () {ll St, Ed; while (~ Scanf ("% d % LLD", & N, & M, & K) {repf (I, 0, n) V [I]. clear (); While (M --) {scanf ("% LLD", & St, & ED); // wa for an hour V [st]. push_back (ed);} repf (I, 1, n) scanf ("% LLD", & P [I]); If (K % P [N]) {puts ("0"); continue;} M. clear (); V [0]. push_back (1); int CNT = 0; For (ll I = 1; I * I <= K; I ++) {If (K % I = 0) {M [I] = CNT ++; m [k/I] = CNT ++ ;}} memset (DP, 0, sizeof (DP )); DP [N] [M [k] = 1; printf ("% LLD \ n", DFS (0, 1) ;}return 0 ;}



Zoj 3644 Kitty's game (DP)

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.