当前位置:网站首页>Niuke winter vacation training camp 4 g (enumeration optimization, Euler power reduction)
Niuke winter vacation training camp 4 g (enumeration optimization, Euler power reduction)
2022-07-03 22:08:00 【seez】
Because it is a subsequence problem , You can find that there are two choices for each element , Choose or not
So there may be 2^n Seed sequence , If you enumerate all the intervals , And find out their maximum and minimum , The time complexity is O(n*2^n)
Because only the maximum and minimum values of each interval are used , So we just need to enumerate the maximum and minimum values , At the same time, we found that because it is a subsequence , Don't care about his position , Because as the most valuable position, it can be arbitrary , So you can sort
So for every point , There are all cases as the maximum and all cases as the minimum , Because the product is , You can list the number of times he takes as the maximum value p, obtain And the number of times as the minimum q, obtain
, Don't worry about the other maximum value matching him
because 2^p and 2^q The time complexity as a power is too high , So we need to use Euler power reduction
number theory --- Euler theorem , Fast power inverse _qq12323qweeqwe The blog of -CSDN Blog
Due to Fermat's small lemma :
Content : Existence prime p,a And p Coprime ==
that q == (p-1)u +v , because a^(p-1)u ==1, So there is one left a^v, So we just need to a Take a module to the power of , You can achieve the effect of power reduction
summary :
- The nature of the topic , Subsequence + The most value , Find that you don't need to care about the location of elements , You can sort in ascending order
- A number position i, As a minimum
As the maximum value
- The product of a number
, Carry out Euler power reduction
#include <iostream>
#include <algorithm>
using namespace std;
const int N=2e5+10;
const int mod=1e9+7;
int a[N];
typedef long long ll;
ll qmi(ll a,ll b,ll mod)
{
ll res=1;
while(b)
{
if(b&1)
res=res*a%mod;
a=a*a%mod;
b>>=1;
}
return res;
}
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i];
ll res=1;
sort(a+1,a+1+n); // The sequence needs to be rearranged
for(int i=1;i<=n;i++)
{
// As a minimum
res=res*qmi(a[i],qmi(2,i-1,mod-1)+qmi(2,n-i,mod-1),mod)%mod;
}
cout<<res;
return 0;
}
边栏推荐
- Solve the problem that openocd fails to burn STM32 and cannot connect through SWD
- Imitation Netease cloud music applet
- Farmersworld farmers world, no faith, how to talk about success?
- JS Demo calcule combien de jours il reste de l'année
- treevalue——Master Nested Data Like Tensor
- 使用dnSpy对无源码EXE或DLL进行反编译并且修改
- 常用sql集合
- [dynamic planning] counting garlic customers: the log of garlic King (the longest increasing public subsequence)
- Oil monkey plug-in
- [sg function] lightoj Partitioning Game
猜你喜欢
Blue Bridge Cup Guoxin Changtian single chip microcomputer -- led lamp module (V)
Collection | pytoch common loss function disassembly
Bluebridge cup Guoxin Changtian single chip microcomputer -- hardware environment (I)
Minio deployment
QFileDialog
(5) User login - services and processes - History Du touch date stat CP
Introduction to kubernetes
2022 safety officer-b certificate examination summary and safety officer-b certificate simulation test questions
What is the difference between res.send() and res.end() in the node express framework
Control loop of program (while loop)
随机推荐
WiFi 2.4g/5g/6g channel distribution
Asynchronous artifact: implementation principle and usage scenario of completable future
Report on the development status and investment planning trends of China's data center industry Ⓡ 2022 ~ 2028
Blue Bridge Cup Guoxin Changtian MCU -- program download (III)
The latest analysis of crane driver (limited to bridge crane) in 2022 and the test questions and analysis of crane driver (limited to bridge crane)
Introduction to kubernetes
Is the account opening of Guotai Junan Securities safe and reliable? How to open Guotai Junan Securities Account
How PHP gets all method names of objects
How PHP adds two numbers
The latest analysis of R1 quick opening pressure vessel operation in 2022 and the examination question bank of R1 quick opening pressure vessel operation
How PHP drives mongodb
Some 5000+ likes, the development notes of a director of cosmic factory, leaked
Common SQL sets
[dynamic planning] counting garlic customers: the log of garlic King (the longest increasing public subsequence)
[sg function]split game (2020 Jiangxi university student programming competition)
DR-AP40X9-A-Qualcomm-IPQ-4019-IPQ-4029-5G-4G-LTE-aluminum-body-dual-band-wifi-router-2.4GHZ-5GHz-QSD
Dynamic research and future planning analysis report of China's urban water supply industry Ⓝ 2022 ~ 2028
Compréhension de la technologie gslb (Global Server load balance)
What should the future of the Internet be like when Silicon Valley employees flee the big factory and rush to Web3| Footprint Analytics
Tidb's initial experience of ticdc6.0