【HDOJ6148】Valley Numer(数位DP)
2024-09-05 17:32:51
题意:
1≤T≤200
● 1≤length(N)≤100
思路:
设f[i,j,k,l]为第i位为j,前i位是否贴上限(0/1),递减或递增(0/1)方案数
g[i,j,k]为不到n位,第i位为j,递减或递增方案数
const mo=;
var f:array[..,..,..,..]of longint;
g:array[..,..,..]of longint;
a:array[..]of longint;
v,n,i,j,k,l,jj,kk,ans,cas,ll:longint;
ch:string; begin readln(cas);
for v:= to cas do
begin
readln(ch);
n:=length(ch);
for i:= to n do a[i]:=;
for i:= to n do a[i]:=ord(ch[i])-ord('');
for i:= to n do
for j:= to do
for k:= to do
for l:= to do f[i,j,k,l]:=;
for i:= to a[]- do f[,i,,]:=;
f[,a[],,]:=;
for i:= to n do
for j:= to do
for k:= to do
for l:= to do
for jj:= to do
begin
if k= then kk:=;
if (k=)and(jj<a[i]) then kk:=;
if (k=)and(jj=a[i]) then kk:=;
if (k=)and(jj>a[i]) then break;
for ll:=l to do
begin
if (ll=)and(j<jj) then continue;
if (ll=)and(j>jj) then continue;
if (ll<>l)and(j=jj) then continue;
f[i,jj,kk,ll]:=(f[i,jj,kk,ll]+f[i-,j,k,l]) mod mo;
end;
end;
for i:= to n- do
for j:= to do
for k:= to do g[i,j,k]:=;
for i:= to do g[,i,]:=;
for i:= to n- do
for j:= to do
for k:= to do
for jj:= to do
for kk:=k to do
begin
if (kk=)and(j<jj) then continue;
if (kk=)and(j>jj) then continue;
if (k<>kk)and(j=jj) then continue;
g[i,jj,kk]:=(g[i,jj,kk]+g[i-,j,k]) mod mo;
end;
ans:=;
for j:= to do
for k:= to do
for l:= to do ans:=(ans+f[n,j,k,l]) mod mo;
for i:= to n- do
for j:= to do
for k:= to do ans:=(ans+g[i,j,k]) mod mo;
writeln(ans);
end; end.
最新文章
- C语言运算符优先级 详细列表
- angularJ之$filter过滤器
- C#多线程之旅(1)——介绍和基本概念
- HoverTree开发日志之验证码
- Linux双机信任,适用统一安装
- FIREFOX A tool for easily making HTTP requests (GET/PUT/POST/DELETE)
- [转](四)unity4.6Ugui中文教程文档-------概要-UGUI Visual Components
- Tarjan算法求有向图的强连通分量
- sql中with as的用法练习
- webpack教程(六)——分离组件代码
- MySQL系列:高可用架构之MHA
- 新概念英语(1-111)The most expensive model
- JS的进阶技巧
- Git .gitignore文件说明
- java 一次CPU占用过高问题的排查及解决
- A new session could not be created. (Original error: Requested a new session but one was in progress) (WARNING: The server did not provide any stacktrace information)
- elasticsearch 安装 windows linux macOS
- cl 命令行配置
- Math.round(),Math.ceil(),Math.floor()
- springboot整合druid数据库连接池并开启监控