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 ...
随机推荐
- JavaScript学习笔记(9)——JavaScript语法之流程控制
javascript的流程控制语句与大部分类c语言一致.大致如下: 一.if if...else if...else if....else if....else..... 二.switch(变量){ ...
- 记个maven无法识别JAVA_HOME的问题 Error: JAVA_HOME is not defined correctly.
Error: JAVA_HOME is not defined correctly. We cannot execute /Library/Java/JavaVirtualMachines/jdk1. ...
- VirtualBox single usermode boot
VirtualBox single usermode boot 当系统因为某些原因无法通过图形界面登录VirtualBox内的系统时,可以通过Grub进入命令行模式/单一用户界面模式. 参考: 1.R ...
- Angle
1 What is Angle. The goal of ANGLE is to allow Windows users to seamlessly run WebGL and other OpenG ...
- RX学习笔记:在FreeCodeCamp的学习
FreeCodeCamp https://www.freecodecamp.com 2016-07-03 前几日在Github浏览时,偶然看到一个叫FreeCodeCamp的开源项目,进去该网站之后感 ...
- SQL技术内幕二DDL
创建数据库: if db_id('DBTest') is nullcreate database DBTest 创建表 use eb_fy_data_test---use 切换所在数据库上下文 if ...
- PythonCrawl自学日志(4)
2016年9月22日10:34:02一.Selector1.如何构建(1)text构建: body = '<html><body><span>good</sp ...
- Python原型模式
如果想根据现有对象复制出新的对象并对其修改,可以考虑原型模式(Prototype Pattern) class Point: __slots__ = ("x", "y&q ...
- Python prettytable的使用方法
Python prettytable的使用方法 prettytable可以整齐地输出一个表格信息: +-----------+------+------------+----------------- ...
- HDFS文件读写流程 (转)
文件读取的过程如下: 使用HDFS提供的客户端开发库Client,向远程的Namenode发起RPC请求: Namenode会视情况返回文件的部分或者全部block列表,对于每个block,Namen ...