hdu4655Cut Pieces
http://acm.hdu.edu.cn/showproblem.php?pid=4655
先以最大的来算为 N*所有的排列数 再减掉重复的 重复的计算方法:取相邻的两个数的最小值再与它前面的组合数和后面的组合数相乘
注意负值
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
using namespace std;
#define LL long long
#define N 1000100
#define mod 1000000007
LL s1[N],s2[N],a[N],b[N];
int main()
{
int i,j,n,t;
cin>>t;
while(t--)
{
cin>>n;
LL s = ;
for(i = ; i <= n ; i++)
{
scanf("%lld",&a[i]);
b[i] = a[i];
s = (s*a[i])%mod;
}
sort(b+,b+n+);
j=;
for(i = ; i <= n ; i++)
if(i%!=)
a[i] = b[++j];
for(i = n ; i >= ; i--)
if(i%==)
a[i] = b[++j];
s1[] = ;
for(i = ; i <= n ; i++)
s1[i] = (s1[i-]*a[i])%mod;
s2[n+] = ;
for(i = n ; i>= ; i--)
s2[i] = (s2[i+]*a[i])%mod;
LL minz;
LL ans = ;
for(i = ; i < n ; i++)
{
minz = min(a[i],a[i+]);
ans=(ans+((s1[i-]*minz)%mod*s2[i+])%mod)%mod;
}
ans = ((s*n)%mod-ans)%mod;
if(ans<)
ans+=mod;
cout<<ans<<endl;
}
return ;
}
hdu4655Cut Pieces的更多相关文章
- HITOJ 2662 Pieces Assignment(状压DP)
Pieces Assignment My Tags (Edit) Source : zhouguyue Time limit : 1 sec Memory limit : 64 M S ...
- 1.4.8 拼凑在一起(putting the pieces together)
putting the pieces together 在最高的级别,schema.xml结构如下, <schema> <types> <fields> <u ...
- uva 12296 Pieces and Discs
题意: 有个矩形,左下角(0,0),左上角(L,W). 思路: 除了圆盘之外,本题的输入也是个PSLG,因此可以按照前面叙述的算法求出各个区域:只需把线段视为直线,用切割凸多边形的方法 :每次读入线段 ...
- Pizza pieces
Pizza pieces Description In her trip to Italy, Elizabeth Gilbert made it her duty to eat perfect piz ...
- HDU 4628 Pieces(DP + 状态压缩)
Pieces 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4628 题目大意:给定一个字符串s,如果子序列中有回文,可以一步删除掉它,求把整个序列删除 ...
- Codeforces 328B-Sheldon and Ice Pieces(馋)
B. Sheldon and Ice Pieces time limit per test 1 second memory limit per test 256 megabytes input sta ...
- 2017 NAIPC A:Pieces of Parentheses
my team solve the problem in the contest with similar ideathis is a more deep analysis The main idea ...
- hdu 4628 Pieces 状态压缩dp
Pieces Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total S ...
- HDU 4655 Cut Pieces(2013多校6 1001题 简单数学题)
Cut Pieces Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)Total ...
随机推荐
- Java快速教程
作者:Vamei 出处:http://www.cnblogs.com/vamei Java是面向对象语言.这门语言其实相当年轻,于1995年才出现,由Sun公司出品.James Gosling ...
- 初学dorado
初学dorado 1.dorado使用视图来写界面代码,超级轻松:还需要画流程,页面间的跳转应该很轻松了. 2.先新建dorado项目,再创建dorado视图 3.在Servers里双击tomacat ...
- POJ 2127 Greatest Common Increasing Subsequence -- 动态规划
题目地址:http://poj.org/problem?id=2127 Description You are given two sequences of integer numbers. Writ ...
- HTML5之图像处理
--- 内嵌图像 - drawImage可以绘制图像context.drawImage(image,dx,dy)context.drawImage(image,dx,dy,dw,dh)context. ...
- Jquery ajax使用json形式通信
前台JS $.ajax({ type: 'post', url: 'HandlerL ...
- 服务控件与html标签的一点
前言 很久没有用服务器控件开发了,在新公司待了三四个月了,这个公司一直都用服务器控件.所以在开发的过程中也发现了一丢丢的东东,也许以前就知道,只是没有认真的发现. 过程 前几天在开发页面的时候,有个需 ...
- thinkphp分页实现
以上为我对于thinkphp分页的实现效果,两种方法,一种调用公共函数中的函数方法(参考http://www.cnblogs.com/tianguook/p/4326613.html),一种是在模型中 ...
- android通过泛型获取控件或视图
@SuppressWarnings("unchecked") public <T extends Fragment> T getFragment(int id) { T ...
- sed线上经典案例之-同时替换多个字符串
回答网友请教的一个问题:配置文件如下:[aaa]cfg1=aaaxxxx=bbbcfg2=ccccfg3=ddd[bbb]cfg1=eeeyyyy=fffcfg2=gggcfg3=hhhcfg4=ii ...
- const用法
一.const作用 二.const用法 1.修饰一般常量 修饰符const可以用在类型说明符前,也可以用在类型说明符后. 例如: ; ; 2.修饰常数组 修饰符const可以用在类型说明符前,也 ...