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教程——int与Integer的区别
首先说一下int和Integer的区别: int 是基本数据类型,Integer是int的包装类.注意:后者的类型是"类".例如使用泛型,List<Integer> n ...
- C++中map用法
/************************************************************************** Map的特点: 1.存储Key-value对* ...
- leetcode Maximal Rectangle 单调栈
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4052721.html 题目链接:leetcode Maximal Rectangle 单调栈 ...
- 【转】循环递归遍历XML文档或按某要求遍历XML文档
<?xml version="1.0" encoding="UTF-8"?> <catalog> <cd> <titl ...
- python(二)基础
1.lambda表达式(一般格式为冒号前边是参数冒号后边是返回值) 单参数: 多参数: 我们如果实现一个普通的filter过滤函数过滤掉偶数: 而我们如果用lambda表达式就很简便: 2.递归 普通 ...
- discuz 重新定义jquery的$
最近做个小插件 发现加了这个代码不执行: $.ajax({ url:'plugin.php?id=register:regeist_jiangsu', type:'post', data:{ 'mob ...
- MySQL基础学习之开始
学习MySQL数据库几个月了,从什么都不懂到现在这个地步,说实话感触很大,也感觉自己有许多不足之处.当接触MySQL的时候, 连创建一个数据表都想了很长的时间,不知道许多东西.幸亏我有一个好的老师,她 ...
- button的相关属性
设置自定义按钮的文字大小 [submit.titleLabel setFont:[UIFont boldSystemFontOfSize:16]]; 设置按钮选中状态的颜色 [btn setTintC ...
- JUnit测试工具在项目中的用法
0:33 2013/6/26 三大框架整合时为什么要对项目进行junit测试: |__目的是测试配置文件对不对,能跑通就可以进行开发了 具体测试步骤: |__1.对hibernate进行测试 配置hi ...
- 使用自定义 URL 实现控制器之间的跳转-b
一个app往往有很多界面,而界面之间的跳转也就是对应控制器的跳转,控制器的跳转一般有两种情况 push 或者 modal,push 和 modal 的默认效果是系统提供的 文章配图 1. 概述 系统提 ...