题目描述

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. C语言 结构体传值与传址分析

    /********************************************************************** * 版权所有 (C)2017, Wang maochun ...

  2. Spring quartz定时任务service注入问题

    今天想单元测试一下spring中的quartz定时任务,job类的大致结构和下面的SpringQtz1类相似,我的是实现的org.quartz.Job接口,到最后总是发现job类里注入的service ...

  3. 对WebView进行的一些设置

    webView.getSettings().setJavaScriptEnabled(true); //使用setting WebSettings webSettings = webView.getS ...

  4. 搭建简单的node+express+mongodb项目

    安装 首先要确保已经安装了 Node.js,接下来创建一个目录,然后进入此目录并将其作为当前工作目录. mkdir myapp cd myapp 通过 npm init 命令为应用创建一个 packa ...

  5. c#开发_Dev的关于XtraGrid的使用(GridControl小结)

    1,增加新行用InitNewRow事件,给新行某字段赋值.后结束编辑. private void grdView_InitNewRow(object sender, DevExpress.XtraGr ...

  6. 引用类型 ( 对象定义 )——Function 类型

    本文地址:http://www.cnblogs.com/veinyin/p/7607798.html  函数实际上是对象,也具有属性和方法,函数名实际上是指向函数对象的指针 function sum( ...

  7. iOS数据存取---iOS-Apple苹果官方文档翻译

    CHENYILONG Blog iOS数据存取---iOS-Apple苹果官方文档翻译 数据存取/*技术博客http://www.cnblogs.com/ChenYilong/ 新浪微博http:// ...

  8. 技巧之如何快速使用websocket来监控标准输出

    为啥是Websocket 服务端可以主动推送消息到浏览器端.比如服务端实时在打印日志,这是一个标准输出,可以实时将日志推送到浏览器. 为啥用websocketd (https://github.com ...

  9. python3.x的HTMLTestRunner.py文件

    """A TestRunner for use with the Python unit testing framework. Itgenerates a HTML re ...

  10. java程序改错题(常见)

    最近跑校招,做了一套java的笔试题. abstract class Name { private String name; public abstract boolean isStupidName( ...