加维降复杂度

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
inline int read()
{
char c = getchar(); while(!isdigit(c)) c = getchar();
int x = ;
while(isdigit(c)) { x = x * + c - ''; c = getchar(); }
return x;
} const int maxn=+;
int mod=;
int T,n,m,k,q,g[maxn][maxn],w[maxn],f[maxn][maxn][maxn][]; bool check(int a,int b,int c)
{
if(abs(w[a]-w[b])>k) return ;
if(abs(w[a]-w[c])>k) return ;
if(abs(w[b]-w[c])>k) return ;
return ;
} int main()
{
scanf("%d",&T); while(T--)
{
scanf("%d%d%d%d",&n,&m,&k,&q);
memset(g,,sizeof g);
for(int i=;i<=n;i++) scanf("%d",&w[i]);
for(int i=;i<=m;i++)
{
int u,v; scanf("%d%d",&u,&v);
g[u][v]=;
}
memset(f,,sizeof f);
for(int i=n;i>=;i--)
{
for(int j=n;j>=;j--)
{
for(int k=n;k>=;k--)
{
if(check(i,j,k)==) f[i][j][k][]=;
else f[i][j][k][]=(f[i][j][k][]+)%mod; for(int s=;s<k;s++)
if(g[s][k]) f[i][j][s][]=(f[i][j][s][]+f[i][j][k][])%mod; for(int s=;s<=j;s++)
if(g[s][j]) f[i][s][k][]=(f[i][s][k][]+f[i][j][k][])%mod; for(int s=;s<=i;s++)
if(g[s][i]) f[s][j][k][]=(f[s][j][k][]+f[i][j][k][])%mod;
}
}
} for(int i=;i<=q;i++)
{
int a,b,c; scanf("%d%d%d",&a,&b,&c);
printf("%d\n",f[a][b][c][]);
}
}
return ;
}

HDU 5807 Keep In Touch的更多相关文章

  1. HDU 5807 Keep In Touch DP

    Keep In Touch Problem Description   There are n cities numbered with successive integers from 1 to n ...

  2. Hdu 5361 In Touch (dijkatrs+优先队列)

    题目链接: Hdu 5361  In Touch 题目描述: 有n个传送机排成一排,编号从1到n,每个传送机都可以把自己位置的东西传送到距离自己[l, r]距离的位置,并且花费c,问从1号传送机到其他 ...

  3. HDU 5361 In Touch (2015 多校6 1009 最短路 + 区间更新)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=5361 题意:最短路.求源点到全部点的最短距离.但与普通最短路不同的是,给出的边是某点到区间[l,r]内随意 ...

  4. 2015 Multi-University Training Contest 6 hdu 5361 In Touch

    In Touch Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total ...

  5. hdu 5533 Dancing Stars on Me 水题

    Dancing Stars on Me Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.p ...

  6. HDU 5536 Chip Factory 字典树

    Chip Factory Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid= ...

  7. HDU 5538 L - House Building 水题

    L - House Building Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.ph ...

  8. HDU 5514 Frogs 容斥定理

    Frogs Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5514 De ...

  9. HDU 5515 Game of Flying Circus 二分

    Game of Flying Circus Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem ...

随机推荐

  1. 如何在IIS8.5上面部署php

    一.开启,设置win8.1自带的IIS 8.5组件服务器. 进入控制面板,选择程序和功能,打开或关闭Windows 功能,找到Internet information services,分别开启FTP ...

  2. 5. test命令

    Shell中的 test 命令用于检查某个条件是否成立,它可以进行数值.字符和文件三个方面的测试. 1. 数值测试 参数 说明 -eq 等于则为真 -ne 不等于则为真 -gt 大于则为真 -ge 大 ...

  3. C++中int转为char 以及int 转为string和string 转int和空格分隔字符串

    1.对于int 转为char 直接上代码: 正确做法: void toChar(int b) { char u; ]; _itoa( b, buffer, ); //正确解法一 u = buffer[ ...

  4. 一:python入门

    Python简介 这点就不做陈述了,相信各位朋友已经已经有了一定的了解. Python特色: 1:简单 第一次接触Python给我的感觉它的语法阅读就像是阅读一本英文书的目录一样,简单易懂,它的语法要 ...

  5. 原生js怎么为动态生成的标签添加各种事件

    这几天用zepto.js写了不少事件,突然想到一个问题,那就是原生的js如何给动态生成的标签添加事件?因为这些标签都是后来通过ajax或者运行其他点击事件生成的,那么如果之前给他们写事件他们这个dom ...

  6. LEK-Introduction-Installation-Usage-new

    LEK is a set of tools which can take data from any source and search, analyze, and visualize it in r ...

  7. windows和Ubuntu双系统的安装和基本操作

    因为最近刚开始学习ubuntu系统,首先要安装系统,搜集了网上的资料觉得这篇博客特别有用  http://www.cnblogs.com/Duane/p/5424218.html,我也是按照里面的步骤 ...

  8. Hive中频繁报警的问题

    在使用Hive的过程中,是不是会在shell中报一堆警告,虽然说不影响正常使用,但是看着很烦人,而且指不定会影响数据的准确性和运行的稳定性. 警告的内容如下: Tue Aug :: CST WARN: ...

  9. Windows下Discuz搭建论坛过程

    搭建环境:Win7 + XAMPP5.5 + Discuz3.2 GBK 官方论坛下载安装包,解压,把upload文件夹拷贝到网站文档根目录(例如我的为:D:\IT\XAMPP5.5\htdocs\) ...

  10. Contest Balloons

    Contest Balloons 题目链接:http://codeforces.com/problemset/problem/725/D 贪心+枚举 每次在排名在自己前面的选出w-t值最小的送气球,更 ...