Codeforces Round #117 (Div. 2) E---wooden Fence (DP)

Source: Internet
Author: User

Vasya have recently bought some land and decided to surround it with a wooden fence.

He went to a company called "wooden Board" the produces wooden boards for fences. Vasya read in the catalog of "the" the company had at its disposal n different types of wood. The company uses the i-th type of wood to produce a board of this type, that's a rectangular ai by bi block.

Vasya decided to order boards in this company and build a fence from them. It turned out that the storehouse of the company are so large that Vasya can order arbitrary number of boards of every type . Note that Vasya are allowed to turn the boards as he builds the fence. However, Vasya cannot turn square boards.

Vasya is required to construct a fence of length l, however, an arbitrary fence won ' t do. Vasya wants his fence to look beautiful. We'll say that a fence be beautiful if and only if the following of the conditions are fulfilled:

In other words, the fence was considered beautiful, if the type of the i-th board in the fence are different from the I?-? 1- TH board ' s type; Besides, the I-TH board ' s length is equal to the I?-? 1-th Board's width (for all I, starting from 2).

Now Vasya wonders, what many variants of arranging a fence for he land exist. Your task is to count the number of different beautiful fences of length L.

Fences would be considered the same if the corresponding sequences of fence boards types and rotations is the same, OT Herwise the fences is different. Since the sought number can be large enough and you need to calculate the answer modulo 1000000007 (109?+?7).
Input

The first line contains integers n and L (1?≤?n?≤?100,?1?≤?l?≤?3000)-the number of different board types and the Fen Ce length, correspondingly. Next n lines contain descriptions of board Types:the i-th line contains both integers ai and bi (1?≤?ai,?bi?≤?100)-the s Izes of the Board of the i-th type. All numbers on the lines is separated by spaces.
Output

Print A single integer-the sought number of variants modulo 1000000007 (109?+?7).
Sample Test (s)
Input

2 3
1 2
2 3

Output

2

Input

1 2
2 2

Output

1

Input

6 6
2 1
3 2
2 5
3 3
5 1
2 1

Output

20

Note

In the first sample there is exactly the variants of arranging a beautiful fence of length 3:

Set DP[I][J] for the length of I, the last board is the scheme number of J, note that if a board is the same length and width, then in any case, can only be one, for the other board, divide it into 2 parts, long as a, width b, length B, Width is a, the same type

/************************************************************************* > File name:cf-117-e.cpp > Aut Hor:alex > Mail: [email protected] > Created time:2015 March 21 Saturday 11:39 10 seconds ******************************* *****************************************/#include <map>#include <set>#include <queue>#include <stack>#include <vector>#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>#include <algorithm>using namespace STD;Const DoublePI =ACOs(-1.0);Const intINF =0x3f3f3f3f;Const DoubleEPS =1e-15;typedef Long LongLL;typedefPair <int,int> PLL;Const intMoD =1000000007; LL dp[3110][ -];structnode{intL, W;intTy;} data[ -];intMain () {intN, L; while(~scanf("%d%d", &n, &l)) {intA, B;intCNT =0;memset(DP,0,sizeof(DP)); for(inti =1; I <= N; ++i) {scanf("%d%d", &a, &b);            DATA[++CNT].L = A;            DATA[CNT].W = b;            Data[cnt].ty = i; DP[A][CNT] =1;if(A! = b)                {data[++cnt].l = b;                DATA[CNT].W = A;                Data[cnt].ty = i; DP[B][CNT] =1; }        } for(inti =1; I <= l; ++i) { for(intj =1; J <= CNT; ++J) {if(Dp[i][j]) { for(intK =1; K <= CNT; ++K) {if(Data[k].ty = = data[j].ty) {Continue; }if(DATA[K].L = = DATA[J].W)                            {dp[i + data[k].l][k] + = dp[i][j];                        Dp[i + data[k].l][k]%= mod; }}}}} LL ans =0; for(inti =1; I <= CNT;            ++i) {ans + = dp[l][i];        Ans%= MoD; }printf("%i64d\n", ans); }return 0;}

Codeforces Round #117 (Div. 2) E---wooden Fence (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.