LightOJ - 1299 - Fantasy Cricket(DP, 数学)
2024-08-22 10:39:25
链接:
https://vjudge.net/problem/LightOJ-1299
题意:
考虑成,U位置的点要往后放,D位置往前放
Dp[i][j]表示处于i位置,还有j个U没有放下。
s[i] == 'D' : Dp[i][j] = Dp[i-1][j]j+Dp[i-1][j+1](j+1)
把d放到前面空出来j的位置中的一个,或者是j+1中的一个同时j+1中的一个U再放下来。
s[i] == 'U' : Dp[i][j] = Dp[i-1][j-1]+Dp[i-1][j]*j
拿起当前U或者,拿起的同时放一个U
代码:
// #include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string.h>
#include<set>
#include<queue>
#include<algorithm>
#include<math.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int MOD = 1e9+7;
const int MAXN = 1e6+10;
int n, m, k;
char s[1010];
LL Dp[1010][1010];
int main()
{
// freopen("test.in", "r", stdin);
int t, cas = 0;
scanf("%d", &t);
while(t--)
{
printf("Case %d:", ++cas);
scanf("%s", s);
int len = strlen(s);
Dp[0][0] = 1;
for (int i = 1;i <= len;i++)
{
if (s[i-1] == 'U')
{
for (int j = 0;j <= len;j++)
Dp[i][j] = (Dp[i-1][j-1]+Dp[i-1][j]*j%MOD)%MOD;
}
else if (s[i-1] == 'D')
{
for (int j = 0;j < len;j++)
Dp[i][j] = (Dp[i-1][j]*j%MOD+Dp[i-1][j+1]*(j+1)%MOD*(j+1)%MOD)%MOD;
}
else
{
for (int j = 0;j <= len;j++)
Dp[i][j] = Dp[i-1][j];
}
}
Dp[len][0] = (Dp[len][0]%MOD+MOD)%MOD;
printf(" %lld\n", Dp[len][0]);
}
return 0;
}
最新文章
- 通过setTimeout来取消因大量计算造成的网页卡顿
- mssql游标实现递归查询
- ZOJ 3908 Number Game ZOJ Monthly, October 2015 - F
- 学会简单使用poi进行excel有关操作
- angular这个大梗的学习笔记
- MySQL Replication 常用架构
- 原生javascript难点总结(1)---面向对象分析以及带来的思考
- authbind start tomcat services as user with less that 1024 ports. linux常规用户使用tomcat的80端口
- CentOS 恢复 rm -rf * 误删数据(转)
- 2016 Multi-University Training Contest 5&;6 总结
- php订单生成唯一Id
- phpmailer发送邮件服务
- IE8 环境的 JQuery 中的 $.ajax 拒绝访问---解决方案
- A Deep Learning-Based System for Vulnerability Detection(一)
- Sitecore8.2 Solr5.1.0配置步骤
- Vue双向数据绑定原理
- Get与Post的主要区别
- 3 第一个Django应用 第2部分(管理站点)
- maven配置jdk1.8环境
- zabbix 官方文档
热门文章
- Asp.net Core CORS 跨域
- Mitsubishi (三菱) Fanuc(发那科),CNC,网口数据采集,NC程序下发(其它品牌CNC,哈斯 马扎克 兄弟等,正在开发中)
- springboot项目 配置https
- gitlab 安装、备份与还原及常见设置
- 基于MBT的自动化测试工具——GraphWalker介绍和实际使用
- IOC+EF+Core项目搭建EF封装(一)
- 【洛谷 P4052】 [JSOI2007]文本生成器(AC自动机,DP)
- cgal的安装、编译
- jmeter用什么查看结果报告
- adb server is out of date. killing... ADB server didn&#39;t ACK * failed to start daemon *……