CF1185G1.Playlist for Polycarp (easy version)

提高+/省选-

通过率:0%

时间限制:5.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

The only difference between easy and hard versions is constraints.

Polycarp loves to listen to music, so he never leaves the player, even on the way home from the university. Polycarp overcomes the distance from the university to the house in exactly TT minutes.

In the player, Polycarp stores nn songs, each of which is characterized by two parameters: tit_i and gig_i, where tit_i is the length of the song in minutes (1≤ti≤151 \le t_i \le 15), gig_i is its genre (1≤gi≤31 \le g_i \le 3).

Polycarp wants to create such a playlist so that he can listen to music all the time on the way from the university to his home, and at the time of his arrival home, the playlist is over. Polycarp never interrupts songs and always listens to them from beginning to end. Thus, if he started listening to the ii-th song, he would spend exactly tit_i minutes on its listening. Polycarp also does not like when two songs of the same genre play in a row (i.e. successively/adjacently) or when the songs in his playlist are repeated.

Help Polycarpus count the number of different sequences of songs (their order matters), the total duration is exactly TT, such that there are no two consecutive songs of the same genre in them and all the songs in the playlist are different.

简单版本与困难版本的唯一区别在于约束条件。

波利卡普喜欢听音乐,因此他从不关闭播放器,甚至在从大学回家的路上也是如此。波利卡普恰好用 TT 分钟走完从大学到家的距离。

播放器中存储了 nn 首歌曲,每首歌曲由两个参数刻画:tit_i 和 gig_i,其中 tit_i 表示该歌曲的时长(单位:分钟,满足 1≤ti≤151 \le t_i \le 15),gig_i 表示其流派(满足 1≤gi≤31 \le g_i \le 3)。

波利卡普希望创建一个播放列表,使得他在从大学回家的整个途中都能持续听音乐,并且在他到家的那一刻,播放列表恰好结束。波利卡普从不中断正在播放的歌曲,总是从头到尾完整听完。因此,若他开始听第 ii 首歌,则恰好花费 tit_i 分钟。此外,波利卡普不喜欢连续(即相邻)播放相同流派的歌曲,也不允许播放列表中出现重复的歌曲。

请帮助波利卡普计算满足以下条件的不同歌曲序列(顺序重要)的数目:

  • 所有歌曲总时长恰好为 TT;
  • 序列中不存在两个相邻歌曲具有相同流派;
  • 播放列表中所有歌曲互不相同。

输入格式

The first line of the input contains two integers nn and TT (1≤n≤15,1≤T≤2251 \le n \le 15, 1 \le T \le 225) — the number of songs in the player and the required total duration, respectively.

Next, the nn lines contain descriptions of songs: the ii-th line contains two integers tit_i and gig_i (1≤ti≤15,1≤gi≤31 \le t_i \le 15, 1 \le g_i \le 3) — the duration of the ii-th song and its genre, respectively.

输入的第一行包含两个整数 nn 和 TT(1≤n≤151 \le n \le 15,1≤T≤2251 \le T \le 225),分别表示播放器中歌曲的数量和所需的总时长。

接下来的 nn 行描述了各首歌曲:第 ii 行包含两个整数 tit_i 和 gig_i(1≤ti≤151 \le t_i \le 15,1≤gi≤31 \le g_i \le 3),分别表示第 ii 首歌曲的时长及其流派。

输出格式

Output one integer — the number of different sequences of songs, the total length of exactly TT, such that there are no two consecutive songs of the same genre in them and all the songs in the playlist are different. Since the answer may be huge, output it modulo 109+710^9 + 7 (that is, the remainder when dividing the quantity by 109+710^9 + 7).

输出一个整数——满足以下条件的不同歌曲序列的数量:序列中所有歌曲的总长度恰好为 TT,序列中不存在两个相邻的歌曲属于同一类型,且播放列表中的所有歌曲互不相同。由于答案可能非常大,请将结果对 109+710^9 + 7 取模(即该数量除以 109+710^9 + 7 所得的余数)。

输入输出样例

  • 输入#1

    3 3
    1 1
    1 2
    1 3

    输出#1

    6
  • 输入#2

    3 3
    1 1
    1 1
    1 3

    输出#2

    2
  • 输入#3

    4 10
    5 3
    2 1
    3 2
    5 1

    输出#3

    10

说明/提示

In the first example, Polycarp can make any of the 66 possible playlist by rearranging the available songs: [1,2,3][1, 2, 3], [1,3,2][1, 3, 2], [2,1,3][2, 1, 3], [2,3,1][2, 3, 1], [3,1,2][3, 1, 2] and [3,2,1][3, 2, 1] (indices of the songs are given).

In the second example, the first and second songs cannot go in succession (since they have the same genre). Thus, Polycarp can create a playlist in one of 22 possible ways: [1,3,2][1, 3, 2] and [2,3,1][2, 3, 1] (indices of the songs are given).

In the third example, Polycarp can make the following playlists: [1,2,3][1, 2, 3], [1,3,2][1, 3, 2], [2,1,3][2, 1, 3], [2,3,1][2, 3, 1], [3,1,2][3, 1, 2], [3,2,1][3, 2, 1], [1,4][1, 4], [4,1][4, 1], [2,3,4][2, 3, 4] and [4,3,2][4, 3, 2] (indices of the songs are given).

在第一个例子中,Polycarp 可以通过重新排列可用的歌曲来构成任意一种 66 种可能的播放列表:[1,2,3][1, 2, 3]、[1,3,2][1, 3, 2]、[2,1,3][2, 1, 3]、[2,3,1][2, 3, 1]、[3,1,2][3, 1, 2] 和 [3,2,1][3, 2, 1](括号内为歌曲的索引)。

在第二个例子中,第一首与第二首歌曲不能连续播放(因为它们属于同一音乐类型)。因此,Polycarp 只能以 22 种可能的方式创建播放列表:[1,3,2][1, 3, 2] 和 [2,3,1][2, 3, 1](括号内为歌曲的索引)。

在第三个例子中,Polycarp 可以制作如下播放列表:[1,2,3][1, 2, 3]、[1,3,2][1, 3, 2]、[2,1,3][2, 1, 3]、[2,3,1][2, 3, 1]、[3,1,2][3, 1, 2]、[3,2,1][3, 2, 1]、[1,4][1, 4]、[4,1][4, 1]、[2,3,4][2, 3, 4] 和 [4,3,2][4, 3, 2](括号内为歌曲的索引)。

输入解题思路,AI测评打分。不知道怎么写?

首页