题目描述

Yuanyuan Long is a dragon like this picture?

                                   
I don’t know, maybe you can ask him. But I’m sure Yuanyuan Long likes ballons, he has a lot of ballons.          

One day, he gets n white ballons and k kinds of pigment, and he thought a problem:

1.      Number these ballons b1, b2,  … , bi, …,  to bn.

2.      Link these ballons to a circle in order, and color these ballons.

3.      He need to make sure that any neighbor ballons have different colors.

He wants to know how many solutions to solve this problem. Can you get the answer to him? The answer maybe very large, get the answer MOD 100000007.

For Example: with 3 ballons and 3 kinds of pigment

Your answer is 3*2*1 MOD 100000007 = 6. 
The answer maybe large, you can use integer type long long.

输入描述:

The first line is the cases T. ( T <=
100)
For next T lines, each line contains n and
k. (2<= n <= 10000, 2<= k
<=100)

输出描述:

For each test case, output the answer on
each line.
示例1

输入

3
3 3
4 2
5 3

输出

6
2
30

题解

$dp$。

$dp[i][j]$表示在第$1$个人涂第一种颜色,涂完$i$个人,且第$i$个人涂第$j$种颜色的方案数。

$sum = dp[n][2]+...+dp[n][k]$,答案就是$sum*k$。

有很多优化可以搞,什么优化都没做就过了......

#include<cstdio>
using namespace std; long long mod = 100000007LL;
long long dp[10010][110]; int main() {
int T, n, k;
scanf("%d", &T);
while(T --) {
scanf("%d%d", &n, &k);
for(int i = 1; i <= n; i ++) {
for(int j = 1; j <= k; j ++) {
dp[i][j] = 0;
}
}
dp[1][1] = 1;
for(int i = 2; i <= n; i ++) {
long long sum = 0;
for(int j = 1; j <= k; j ++) {
sum = (sum + dp[i - 1][j]) % mod;
}
for(int j = 1; j <= k; j ++) {
dp[i][j] = (sum - dp[i - 1][j] + mod) % mod;
}
}
long long sum = 0;
for(int j = 2; j <= k; j ++) {
sum = (sum + dp[n][j]) % mod;
}
sum = sum * k % mod;
printf("%lld\n", sum);
}
return 0;
}

  

湖南大学ACM程序设计新生杯大赛(同步赛)H - Yuanyuan Long and His Ballons的更多相关文章

  1. 湖南大学ACM程序设计新生杯大赛(同步赛)J - Piglet treasure hunt Series 2

    题目描述 Once there was a pig, which was very fond of treasure hunting. One day, when it woke up, it fou ...

  2. 湖南大学ACM程序设计新生杯大赛(同步赛)A - Array

    题目描述 Given an array A with length n  a[1],a[2],...,a[n] where a[i] (1<=i<=n) is positive integ ...

  3. 湖南大学ACM程序设计新生杯大赛(同步赛)L - Liao Han

    题目描述 Small koala special love LiaoHan (of course is very handsome boys), one day she saw N (N<1e1 ...

  4. 湖南大学ACM程序设计新生杯大赛(同步赛)B - Build

    题目描述 In country  A, some roads are to be built to connect the cities.However, due to limited funds, ...

  5. 湖南大学ACM程序设计新生杯大赛(同步赛)I - Piglet treasure hunt Series 1

    题目描述 Once there was a pig, which was very fond of treasure hunting. The treasure hunt is risky, and ...

  6. 湖南大学ACM程序设计新生杯大赛(同步赛)E - Permutation

    题目描述 A mod-dot product between two arrays with length n produce a new array with length n. If array ...

  7. 湖南大学ACM程序设计新生杯大赛(同步赛)D - Number

    题目描述 We define Shuaishuai-Number as a number which is the sum of a prime square(平方), prime cube(立方), ...

  8. 湖南大学ACM程序设计新生杯大赛(同步赛)G - The heap of socks

    题目描述 BSD is a lazy boy. He doesn't want to wash his socks, but he will have a data structure called ...

  9. 湖南大学ACM程序设计新生杯大赛(同步赛)C - Do you like Banana ?

    题目描述 Two endpoints of two line segments on a plane are given to determine whether the two segments a ...

随机推荐

  1. proxy vue3.0

    <html> <head> <meta charset="UTF-8" /> <meta name="viewport" ...

  2. 在Centos系统下使用命令安装gnome图形界面程序

    第一步:先检查yum 是否安装了,以及网络是否有网络.如果这两者都没有,先解决网络,在解决yum的安装. 第二步:在命令行下 输入下面的命令来安装Gnome包. # yum groupinstall ...

  3. HDU 6158 笛卡尔定理 几何

    LINK 题意:一个大圆中内切两个圆,三个圆两两相切,再不断往上加新的相切圆,问加上的圆的面积和.具体切法看图 思路:笛卡尔定理: 若平面上四个半径为r1.r2.r3.r4的圆两两相切于不同点,则其半 ...

  4. SMTP暴力破解

    这里实现一个SMTP的暴力破解程序,实验搭建的是postfix服务器,猜解用户名字典(user.txt)和密码字典(password.txt)中匹配的用户名密码对, 程序开发环境是: WinXP VC ...

  5. eclipse加速/Nginx配置跨域代理

    下班时间到啦! --下班都是他们的,而我,还是什么都没有. eclipse加速 去掉包含js文件的包的js验证,否则每次启动都需要进行校验(右击项目->properties) Nginx配置跨域 ...

  6. 组合数+逆元 A - Chat Group Gym - 101775A

    题目链接:https://cn.vjudge.net/contest/274151#problem/A 具体思路:我们可以先把所有的情况算出来,为2^n.然后不合法的情况减去就可以了.注意除法的时候要 ...

  7. mysq配置

    mysql运维 1.mysql配置文件:/etc/my.cnf mysql日记文件 :安装时候配置的,可以通过ps aux|grep mysqld 查询 ps aux|grep mysqld mysq ...

  8. 大端小端转换,le32_to_cpu 和cpu_to_le32

    字节序 http://oss.org.cn/kernel-book/ldd3/ch11s04.html 小心不要假设字节序. PC 存储多字节值是低字节为先(小端为先, 因此是小端), 一些高级的平台 ...

  9. 123.Best Time to Buy and Sell Stock III---dp

    题目链接:https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iii/description/ 题目大意:与122题类似,只是这 ...

  10. caffe Python API 之Model训练

    # 训练设置 # 使用GPU caffe.set_device(gpu_id) # 若不设置,默认为0 caffe.set_mode_gpu() # 使用CPU caffe.set_mode_cpu( ...