Codeforces Round #117 (Div. 2)E---Wooden Fence(dp)

Codeforces Round #240 (Div. 1)B---Mashmokh and ACM(水dp) Mashmokh’s boss, Bimokh, didn’t like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh’s team. I 阅读详情

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

He went to a company called “Wooden board” that produces wooden boards for fences. Vasya read in the catalog of products that the company has 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 is 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 is so large that Vasya can order arbitrary number of boards of every type. Note that Vasya is 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 is beautiful if and only if the following two conditions are fulfilled:

there are no two successive boards of the same type
the first board of the fence has an arbitrary length, and the length of each subsequent board equals the width of the previous one 

In other words, the fence is considered beautiful, if the type of the i-th board in the fence is 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, how many variants of arranging a fence for his land exist. Your task is to count the number of different beautiful fences of length l.

Two fences will be considered the same if the corresponding sequences of fence boards types and rotations are the same, otherwise the fences are different. Since the sought number can be large enough, you need to calculate the answer modulo 1000000007 (109 + 7).
Input

The first line contains two integers n and l (1 ≤ n ≤ 100, 1 ≤ l ≤ 3000) — the number of different board types and the fence length, correspondingly. Next n lines contain descriptions of board types: the i-th line contains two integers ai and bi (1 ≤ ai, bi ≤ 100) — the sizes of the board of the i-th type. All numbers on the lines are 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 are exactly two variants of arranging a beautiful fence of length 3:

As the first fence board use the board of the first type of length 1 and width 2. As the second board use board of the second type of length 2 and width 3.
Use one board of the second type after you turn it. That makes its length equal 3, and width — 2. 

设dp[i][j] 表示长度为i,最后一个board是j的方案数,注意,如果一个board的长和宽一样,那么无论如何放置,只能算一种,对于其他的board,把它分成2份,长为a,宽为b;长为b,宽为a,类型相同

/*************************************************************************
    > File Name: CF-117-E.cpp
    > Author: ALex
    > Mail: zchao1995@gmail.com 
    > Created Time: 2015年03月21日 星期六 11时39分10秒
 ************************************************************************/

#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 double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
const double eps = 1e-15;
typedef long long LL;
typedef pair <int, int> PLL;

const int mod = 1000000007;
LL dp[3110][220];

struct node
{
    int l, w;
    int ty;
}data[220];

int main()
{
    int n, l;
    while (~scanf("%d%d", &n, &l))
    {
        int a, b;
        int cnt = 0;
        memset(dp, 0, sizeof(dp));
        for (int i = 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 (int i = 1; i <= l; ++i)
        {
            for (int j = 1; j <= cnt; ++j)
            {
                if (dp[i][j])
                {
                    for (int k = 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 (int i = 1; i <= cnt; ++i)
        {
            ans += dp[l][i];
            ans %= mod;
        }
        printf("%I64d\n", ans);
    }
    return 0;
}
Codeforces Round #169 (Div. 2)---C. Little Girl and Maximum Sum(简单贪心) The little girl loves the problems on array queries very much.One day she came across a rather well-known problem: you’ve got an array of n elements (the elements of the array are indexed starting from 阅读详情

相关推荐

qt使用qxlsx实现xlsx、xls表格文件快速写入和读取

新年第二篇文章,收尾一个去年计划中发表文章和实现功能。

kbq的博客 1万+

Codeforces Round #324 (Div. 2)C. Marina and Vasya

A的万般无奈。。。后来跑了大牛的这份代码发现, 题意是求一个序列与给定的两个序列有t个不同。 只要保证。。。对应位置就行了。。 所以处理起来非常方便。。。。。。。。。。。。。。 可是没有感觉是对应位置啊瞎几把想了一堆。后来真的是。 再后来? 我觉得非常好的就是又多了那么点见识。。 #include <bits/stdc++.h> using nam...

weixin_30323961的博客 121

【2022KaliLinux】openvas/gvm 没有scan configs 或者是 scan config error “XXXXXXXXXXX”

gvm/openvas的configuration的scan config为空

zbossz的学习小分队 3606

Vasya and Digital Root

Vasya has recently found out what a digital root of a number is and he decided to share his knowledge with you. Let’s assume that S(n) is the sum of digits of number n, for example, S(4098) = 4 + 0 + ...

qq_45067380的博客 256

保姆级教程:用GEE(Google Earth Engine)复现CASA模型计算NPP,附完整数据集清单与Python代码

本文提供了一份详细的保姆级教程,指导如何使用GEE(Google Earth Engine)复现CASA模型计算NPP(净初级生产力)。教程涵盖环境准备、关键数据集获取与处理、Python代码实现全流程,以及结果验证与常见问题解决方案,帮助生态学研究者高效完成NPP计算。

weixin_28707365的博客 334

HFSS仿真中如何提取最大E/H场强与频率关系曲线

本文详细讲解了在HFSS仿真中提取最大E/H场强与频率关系曲线的完整流程。通过使用场计算器(Field Calculator)和创建场报告,工程师可以准确获得器件在整个频带内的电场或磁场强度峰值,并进一步推导出关键的功率容量曲线,为高功率射频器件(如滤波器、耦合器)的设计提供至关重要的安全评估依据。

ss78901的博客 1099

codeforces Wooden Fence 简单DP

题意:给你N种模板,题中规定了几个要求,要求搭长度为l的墙,问有几种搭法(所谓不同就是抽象之后的墙中每种墙的排列方式不同)。 做法:首先增加木板,把竖着放和横着放的木板当成两种,但这只限于a,b不同的木板,然后在建立数组mp,因为碍于题意,竖着和横着的木板其实是同一种木板,然后建立状态dp[i][j],长度为i的墙的最后是第j种木板。 #include #include #includ

uiiの技术随笔 505

python 常见算法(1-50题)

常见的算法题

weixin_58470558的博客 1757

codeforces Round #117 Div.2 182E. Wooden Fence

#include&lt;iostream&gt; #include&lt;cstdio&gt; #include&lt;cstring&gt; #include&lt;cmath&gt; #include&lt;queue&gt; #include&lt;stack&gt; #include&lt;algorithm&gt; #include&lt;cmath&gt; #inclu

hududumo 135

TikTok Shop API密钥获取与PHP实战对接指南

本文详细介绍了TikTok Shop API密钥的获取流程与PHP实战对接方法。从开发者后台创建应用、获取核心的API密钥开始,逐步解析OAuth 2.0授权机制,并提供了完整的PHP封装类示例,涵盖签名生成、API调用、令牌刷新及错误处理,帮助开发者快速实现与TikTok Shop的数据对接与自动化操作。

weixin_29300241的博客 403

电磁兼容(EMC)整改案例(七):EFT测试失败都是IC悬空引脚惹的祸

无论任何时候,为了避免这些问题,通常建议对悬空的IO口进行适当的配置,比如设置为强推挽输出低电平、输入带上拉或下拉电阻等,以减少外部电路对IO管脚状态的影响,并提高系统的稳定性和可靠性.

linkking27的博客 1032

Codeforces Round #177 (Div. 2)---D. Polo the Penguin and Houses (组合数学+暴力)

Little penguin Polo loves his home village. The village has n houses, indexed by integers from 1 to n. Each house has a plaque containing an integer, the i-th house has a plaque containing integer pi (

Alex 2169

Qt(C++)使用QChart动态显示3个设备的温度变化曲线

Qt的QChart是一个用于绘制图表和可视化数据的类。提供了一个灵活的、可扩展的、跨平台的图表绘制解决方案,可以用于各种应用程序,如数据分析、科学计算、金融交易等。

1917

ZeptoLab Code Rush 2015---C. Om Nom and Candies

A sweet little monster Om Nom loves candies very much. One day he found himself in a rather tricky situation that required him to think a bit in order to enjoy candies the most. Would you succeed with

Alex 1959

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

Codeforces Round #292 (Div. 1)---A. Drazil and Factorial

Drazil is playing a math game with Varda.Let’s define for positive integer x as a product of factorials of its digits. For example, .First, they choose a decimal number a consisting of n digits that co

Alex 1510

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

Codeforces Round #291 (Div. 2)---D. R2D2 and Droid Army

time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard outputAn army of n droids is lined up in one row. Each droid is described by m integers a1,

Alex 1302

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

Codeforces Round #305 (Div. 2)C---Mike and Frog(扩欧+乱搞)

Mike has a frog and a flower. His frog is named Xaniar and his flower is named Abol. Initially(at time 0), height of Xaniar is h1 and height of Abol is h2. Each second, Mike waters Abol and Xaniar.So,

Alex 1292

Codeforces Round #177 (Div. 2)---E. Polo the Penguin and XOR operation(贪心)

Little penguin Polo likes permutations. But most of all he likes permutations of integers from 0 to n, inclusive.For permutation p = p0, p1, …, pn, Polo has defined its beauty — number .Expression mean

Alex 1275

Codeforces Round #214 (Div. 2)---C. Dima and Salad

Dima, Inna and Seryozha have gathered in a room. That’s right, someone’s got to go. To cheer Seryozha up and inspire him to have a walk, Inna decided to cook something.Dima and Seryozha have n fruits i

Alex 1257

Codeforces Round #294 (Div. 2)---E. A and B and Lecture Rooms

A and B are preparing themselves for programming contests.The University where A and B study is a set of rooms connected by corridors. Overall, the University has n rooms connected by n - 1 corridors s

Alex 1247

Codeforces Round #170 (Div. 2)---C. Learning Languages(并查集)

The “BerCorp” company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee w

Alex 1238

Codeforces Round #240 (Div. 1)---B.Mashmokh and ACM(dp)

Mashmokh’s boss, Bimokh, didn’t like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh’s team. I

Alex 1236

Codeforces Round #299 (Div. 2)

A题,水题,注意单词别打错了/************************************************************************* > File Name: CF-299-A.cpp > Author: ALex > Mail: zchao1995@gmail.com > Created Time: 2015年04月15

Alex 1233

Codeforces Round #113 (Div. 2)E---Tetrahedron(矩阵,水题)

You are given a tetrahedron. Let’s mark its vertices with letters A, B, C and D correspondingly.An ant is standing in the vertex D of the tetrahedron. The ant is quite active and he wouldn’t stay idle.

Alex 1222

Codeforces Round #172 (Div. 2)---D. Maximum Xor Secondary(RMQ + 二分)

Bike loves looking for the second maximum element in the sequence. The second maximum element in the sequence of distinct numbers x1, x2, …, xk (k > 1) is such maximum element xj, that the following in

Alex 1221
上一篇: Codeforces Round #113 (Div. 2)E---Tetrahedron(矩阵,水题)
下一篇: VK Cup 2015 - Round 1 (unofficial online mirror, Div. 1 only)E---The Art of Dealing with ATM
tokers
博客等级 码龄12年 71粉丝 700原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值