bzoj4664: Count
是bzoj4498: 魔法的碰撞的哥哥题,我只写了一种
不一样的地方在于贡献有负数,第三维要保存的不能仅仅是0~L,这样空间会炸裂
考虑如何把贡献变成正的
假如要求最优解,那么一定是按顺序排,混乱度为hmax-hmin
反过来想,这启示我们hi-hj,可以用(hi - hi-1)+(hi-1 - hi-2)……(hj+1 - hj)表示出来
那么可以从小到大插入,每次插入给所有段的两端的点的贡献加上hi - hi-1
好妙啊
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long LL;
const int _=1e2;
const int maxn=1e2+;
const int maxL=1e3+_;
const LL mod=1e9+; int h[maxn];
LL f[][maxn][maxL][];
int main()
{
// freopen("b.in","r",stdin);
// freopen("b.out","w",stdout);
int n,L;
scanf("%d%d",&n,&L);
if(n==){puts("");return ;}
for(int i=;i<=n;i++)scanf("%d",&h[i]);
sort(h+,h+n+);
if(h[n]-h[]>L){puts("");return ;} int now=;
f[now][][][]=;
f[now][][][]=;
for(int i=;i<n;i++)
{
memset(f[now^],,sizeof(f[now^]));
for(int j=;j<=i;j++)
for(int k=;k<=L;k++)
for(int p=;p<=;p++)
if(f[now][j][k][p])
{
int d=k+(h[i+]-h[i])*(*j-p);
if(d<=L)
{
f[now^][j+][d][p]=(f[now^][j+][d][p]+f[now][j][k][p]*(j-p+))%mod;
f[now^][j][d][p]=(f[now^][j][d][p]+f[now][j][k][p]*(*j-p))%mod;
if(j!=)f[now^][j-][d][p]=(f[now^][j-][d][p]+f[now][j][k][p]*(j-))%mod;
if(p!=)
{
f[now^][j+][d][p+]=(f[now^][j+][d][p+]+f[now][j][k][p]*(-p))%mod;
f[now^][j][d][p+]=(f[now^][j][d][p+]+f[now][j][k][p]*(-p))%mod;
}
}
}
now^=;
} LL ans=;
for(int i=;i<=L;i++)
ans=(ans+f[now][][i][])%mod;
printf("%lld\n",ans); return ;
}
bzoj4664: Count的更多相关文章
- nodejs api 中文文档
文档首页 英文版文档 本作品采用知识共享署名-非商业性使用 3.0 未本地化版本许可协议进行许可. Node.js v0.10.18 手册 & 文档 索引 | 在单一页面中浏览 | JSON格 ...
- C#中Length和Count的区别(个人观点)
这篇文章将会很短...短到比你的JJ还短,当然开玩笑了.网上有说过Length和count的区别,都是很含糊的,我没有发现有 文章说得比较透彻的,所以,虽然这篇文章很短,我还是希望能留在首页,听听大家 ...
- [PHP源码阅读]count函数
在PHP编程中,在遍历数组的时候经常需要先计算数组的长度作为循环结束的判断条件,而在PHP里面对数组的操作是很频繁的,因此count也算是一个常用函数,下面研究一下count函数的具体实现. 我在gi ...
- EntityFramework.Extended 实现 update count+=1
在使用 EF 的时候,EntityFramework.Extended 的作用:使IQueryable<T>转换为update table set ...,这样使我们在修改实体对象的时候, ...
- 学习笔记 MYSQL报错注入(count()、rand()、group by)
首先看下常见的攻击载荷,如下: select count(*),(floor(rand(0)*2))x from table group by x; 然后对于攻击载荷进行解释, floor(rand( ...
- count(*) 与count (字段名)的区别
count(*) 查出来的是:结果集的总条数 count(字段名) 查出来的是: 结果集中'字段名'不为空的记录的总条数
- BZOJ 2588: Spoj 10628. Count on a tree [树上主席树]
2588: Spoj 10628. Count on a tree Time Limit: 12 Sec Memory Limit: 128 MBSubmit: 5217 Solved: 1233 ...
- [LeetCode] Count Numbers with Unique Digits 计算各位不相同的数字个数
Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...
- [LeetCode] Count of Range Sum 区间和计数
Given an integer array nums, return the number of range sums that lie in [lower, upper] inclusive.Ra ...
随机推荐
- POJ1635 树的最小表示法(判断同构)
Some major cities have subway systems in the form of a tree, i.e. between any pair of stations, ther ...
- 洛谷 [P3205] 合唱队
区间DP 手动模拟一下,我们发现本题就是一个左右加数的区间DP #include <iostream> #include <cstdio> #include <cstri ...
- POJ2486 Apple Tree
Time Limit: 1000MS Memory Limit: 65536KB 64bit IO Format: %lld & %llu Description Wshxzt is ...
- ADO:防止更新的数据含有单引号而出错
原文发布时间为:2008-08-01 -- 来源于本人的百度文章 [由搬家工具导入] public void Update( string au_lname, string zip,string au ...
- oracle 连接数据库以及查看当前用户、当前数据库实例
sql>show user;查看当前用户 sql>show parameter instance_name;查看当前数据库实例 例如: sqlplus登录:用sys用户登录(密码是1234 ...
- 标准C程序设计七---03
Linux应用 编程深入 语言编程 标准C程序设计七---经典C11程序设计 以下内容为阅读: <标准C程序设计>(第7版) 作者 ...
- HDU 4920 Matrix multiplication(bitset优化)
题目链接 Matrix multiplication 求矩阵A和B相乘的结果. 因为答案只要对3取模,所以我们可以通过一些方法来加速计算. 我们对两个矩阵各开两个bitset,分别存储模3余1和模3余 ...
- T1077 多源最短路 codevs
http://codevs.cn/problem/1077/ 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 已知n个点(n&l ...
- luogu P1886 滑动窗口(单调队列
题目描述 现在有一堆数字共N个数字(N<=10^6),以及一个大小为k的窗口.现在这个从左边开始向右滑动,每次滑动一个单位,求出每次滑动后窗口中的最大值和最小值. 例如: The array i ...
- 阿里云***(java应用)
阿里云***(FQ)实战 前言 因为公司涉及国外业务,依赖于google的map服务,生产环境我们使用的是亚马逊服务器,所以访问google地图没问题,但是国内的开发.测试环境,使用的是阿里云,想 ...