首页 技术 正文
技术 2022年11月20日
0 收藏 391 点赞 2,376 浏览 3057 个字

Yue Fei’s Battle

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others)
Total Submission(s): 760    Accepted Submission(s): 266

Problem DescriptionYue Fei is one of the most famous military general in Chinese history.He led Southern Song army in the wars against the Jin dynasty of northern China. Yue Fei achieved a lot of victory and hopefully could retake Kaifeng ,the former capital of Song occupied by Jin. Fearing that retaking Kaifeng might cause the Jin to release former Emperor Song Qinzong, threatening his throne, Emperor Song Gaozong took some corrupted officers’ advice, sending 12 urgent orders in the form of 12 gold plaques to Yue Fei, recalling him back to the capital.

Then Yue Fei was put into prison and was killed under a charge of “maybe there is” treason. But later Yue Fei was posthumously pardoned and rehabilitated, and became a symbol of loyalty to the country. The four corrupted officers who set him up were Qin Hui,Qin Hui’s wife Lady Wang, Moqi Xie and Zhang Jun. People made kneeling iron statues of them and put the statues before Yue Fei’s tomb (located by the West Lake, Hangzhou). For centuries, these statues have been cursed, spat and urinated upon by people. (Now please don’t do that if you go to Hangzhou and see the statues.)

One of the most important battle Yue Fei won is the battle in Zhuxian town. In Zhuxian town, Yue Fei wanted to deploy some barracks, and connected those barracks with roads. Yue Fei needed all the barracks to be connected, and in order to save money, he wanted to build as less roads as possible. There couldn’t be a barrack which is too important, or else it would be attacked by enemies. So Yue Fei required that NO barrack could connect with more than 3 roads. According to his battle theory, Yue Fei also required that the length of the longest route among the barracks is exactly K. Note that the length of a route is defined as the number of barracks lied on it and there may be several longest routes with the same length K.

Yue Fei wanted to know, in how many different ways could he deploy the barracks and roads. All barracks could be considered as no different. Yue Fei could deploy as many barracks as he wanted.

For example, if K is 3,Yue Fei had 2 ways to deploy the barracks and roads as shown in figure1. If K is 4, the 3 kinds of layouts is shown in figure 2. (Thick dots stand for barracks, and segments stand for roads):

动态规划(计数DP):HDU 5136 Yue Fei's Battle
Please bring your computer and go back to Yue Fei’s time to help him so that you may change the history. InputThe input consists of no more than 25 test cases.

For each test, there is only one line containing a integer K(1<=K<=100,000) denoting the length of the longest route.

The input ends by K = 0.

 OutputFor each test case, print an integer denoting the number of different ways modulo 1000000007. Sample Input340 Sample Output23   这道题就是一个简单的DP。动态规划(计数DP):HDU 5136 Yue Fei's Battle动态规划(计数DP):HDU 5136 Yue Fei's Battle

  引用了别人的题解。

 #include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int N=,Mod=;
long long dp[N],sum[N],ans;int T,n;
long long Inv(long long x){
return x==?:(Mod-Mod/x)*Inv(Mod%x)%Mod;
}
long long i2,i6;
int main(){
sum[]=;dp[]=;
sum[]=;dp[]=;
i2=Inv();i6=Inv();
for(int i=;i<N;i++){
dp[i]=dp[i-]*(dp[i-]+)%Mod*i2%Mod;
(dp[i]+=dp[i-]*sum[i-]%Mod)%=Mod;
sum[i]=(sum[i-]+dp[i])%Mod;
} while(scanf("%d",&n)!=EOF&&n){
if(n==){printf("1\n");continue;}
else if(n%==){
ans=sum[n/-]*(dp[n/]*(dp[n/]+)%Mod*i2%Mod)%Mod;
ans+=dp[n/]*(dp[n/]-+Mod)%Mod*(dp[n/]-+Mod)%Mod*i6%Mod;
ans=((ans+dp[n/]*(dp[n/]-+Mod)%Mod)%Mod+dp[n/])%Mod;
}
else ans=dp[n/]*(dp[n/]+)%Mod*i2%Mod;
printf("%lld\n",ans);
}
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,080
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,554
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,403
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,178
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,815
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,898