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培训(1-4节课)
课程安排:JavaEE方向(控制台程序,GUI程序,Web程序,手机程序)(dos命令是控制台程序:QQ是GUI程序,放在计算机上:QQ空间是Web程序,放在腾讯公司) 讲课的13本教材:C语言,Ja ...
- C# 实现对窗体(Form)换肤
http://www.csharpwin.com/csharpresource/2992.shtml 一直想写一个比较完整的.容易扩展的窗体换肤的方案,由于时间问题,都没去实现这个想法.现在有朋友提出 ...
- C# WinForm动态控件实例:口算训练
昨天晚上回寝室看到室友正在被一个C#课的作业苦恼,作业的内容是编写一个口算训练程序,能够实现随意添加题目数量.于是,喜欢写C#的我就决定解救一下他们. 创建动态控件 既然要动态添加,那就必须使用动态控 ...
- CentOS 最小化安装后安装桌面
通过yum的方式安装: yum groupinstall -y "Desktop" "Desktop Platform" "Desktop ...
- JAVA获取当前日期以及将字符串转成指定格式的日期
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ pac ...
- 对于python WSGI的理解
首先看看WSGI的目的是什么? 是用来定义一个统一的接口. 这个接口是针对Web服务器和python Web应用之间的. 以增加Python web应用在不同Web 服务器之间的可移植性. 也就是说如 ...
- poj 2001 Shortest Prefixes trie入门
Shortest Prefixes 题意:输入不超过1000个字符串,每个字符串为小写字母,长度不超过20:之后输出每个字符串可以简写的最短前缀串: Sample Input carbohydrate ...
- Unity3d Shader开发(二)SubShader
(1)SubShader Unity中的每一个着色器都包含一个subshader的列表,当Unity需要显示一个网格时,它能发现使用的着色器,并提取第一个能运行在当前用户的显示卡上的子着色器. 当Un ...
- Android初步 简单demo
刚入门不久,没学JAVA,从C++转过来的,C++的QT和安卓简直有异曲同工之妙,为了加深自己对安卓的理解,特写博客以记录,望大神们多多指点. 效果图,刚入门的话,肯定要熟悉基本的控件的使用,这跟我学 ...
- Mongodb介绍
MongoDB 是一个高性能,开源,无模式的文档型数据库,是当前noSql数据库产品中最热门的一种.它在许多场景下用于替代传统的关系型数据库或键值对存储方式,MongoDB是用C++开发,MongoD ...