湖南大学ACM程序设计新生杯大赛(同步赛)H - Yuanyuan Long and His Ballons
题目描述
Yuanyuan Long is a dragon like this picture?
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
输入描述:
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.
输入
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的更多相关文章
- 湖南大学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 ...
- 湖南大学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 ...
- 湖南大学ACM程序设计新生杯大赛(同步赛)L - Liao Han
题目描述 Small koala special love LiaoHan (of course is very handsome boys), one day she saw N (N<1e1 ...
- 湖南大学ACM程序设计新生杯大赛(同步赛)B - Build
题目描述 In country A, some roads are to be built to connect the cities.However, due to limited funds, ...
- 湖南大学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 ...
- 湖南大学ACM程序设计新生杯大赛(同步赛)E - Permutation
题目描述 A mod-dot product between two arrays with length n produce a new array with length n. If array ...
- 湖南大学ACM程序设计新生杯大赛(同步赛)D - Number
题目描述 We define Shuaishuai-Number as a number which is the sum of a prime square(平方), prime cube(立方), ...
- 湖南大学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 ...
- 湖南大学ACM程序设计新生杯大赛(同步赛)C - Do you like Banana ?
题目描述 Two endpoints of two line segments on a plane are given to determine whether the two segments a ...
随机推荐
- 随机切分csv训练集和测试集
使用numpy切分训练集和测试集 觉得有用的话,欢迎一起讨论相互学习~Follow Me 序言 在机器学习的任务中,时常需要将一个完整的数据集切分为训练集和测试集.此处我们使用numpy完成这个任务. ...
- centos7 网络问题
1虚拟机网卡设置--网卡设置模式为NET模式(正常情况是可以直接上网的)2“cd /etc/sysconfig/network-scripts/3使用命令“sudo vi ifcfg-ens33”进入 ...
- Python学习笔记(九)返回函数
摘抄:https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/0014318352367 ...
- 【最大流】【CODEVS】1993 草地排水
[算法]网络流-最大流(dinic) [题解]http://www.cnblogs.com/onioncyc/p/6496532.html #include<cstdio> #includ ...
- 【BZOJ】1597 [Usaco2008 Mar]土地购买
[算法]DP+斜率优化 [题意]n(n≤50000)块土地,长ai宽bi,可分组购买,每组代价为max(ai)*max(bi),求最小代价. [题解] 斜率优化:http://www.cnblogs. ...
- 【BZOJ】4293: [PA2015]Siano 线段树上二分
[题意]给定n棵高度初始为0的草,每天每棵草会长高a[i],m次收割,每次在d[i]天将所有>b[i]的草收割到b[i],求每次收割量.n<=500000. [算法]线段树上二分 [题解] ...
- python操作YAML文件之pyyaml库
1. YAML简介 YAML是一种被认为可以超越XML.JSON的配置文件,最早接触是Spring Boot,木有想到python也是支持的,遂研究一下. python解析YAML库叫做pyyaml, ...
- stanfordCorenlp在python3中的安装使用+词性学习
1 安装 前言 Stanford CoreNLP的源代码是使用Java写的,提供了Server方式进行交互.stanfordcorenlp是一个对Stanford CoreNLP进行了封装的Pytho ...
- appium===常用方法介绍,元素定位
https://testerhome.com/topics/3711 元素定位方法: find_element_by_android_uiautomator ,使用uiautomator定位,后面参数 ...
- c# 使用httpclient
using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using ...