拉格朗日差值 - 杜教板子

 

牛客网暑期ACM多校训练营(第一场) F Sum of Maximum

杜教板子:

证明https://blog.csdn.net/Lee_w_j__/article/details/81135539

#include <cstdio>
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <cstring>
#include <queue>
#include <stack>
#include <ctime>
#include <complex>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define forn(i,n) for(int i = 0;i<n;i++)
#define for1(i,n) for(int i = 1;i<=n;i++)
#define pb push_back
//#define mp make_pair
#define all(x) (x).begin(),(x).end()
//#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef unsigned us;
typedef unsigned long long ull;
const ll mod=1e9+7;
const int inf = 1000000000;
const int maxn = 1003005;
const int maxa = 300005;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; if(b<0) return -1; for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int INF = 10000000;
//ll fac(ll a) {ll ans = 1;for(int i = 1;i<=a;i++) ans*=i;return a==0?1:ans;};
//start = clock();
//finish = clock();
//cout<<double(finish - start) / CLOCKS_PER_SEC<<" seconds"<<endl;
//rep(i,2,100002) inv[i] = inv[mod%i]*(mod-mod/i)%mod; //
clock_t start,finish;
//double duration;
//long double eps = 1e-10;//You wanna hack this? Are you Serious?namespace polysum {const int D=3001000;ll a[D],f[D],g[D],p[D],p1[D],p2[D],b[D],h[D][2],C[D];ll calcn(int d,ll *a,ll n) {if (n<=d) return a[n];p1[0]=p2[0]=1;rep(i,0,d+1) {ll t=(n-i+mod)%mod;p1[i+1]=p1[i]*t%mod;}rep(i,0,d+1) {ll t=(n-d+i+mod)%mod;p2[i+1]=p2[i]*t%mod;}ll ans=0;rep(i,0,d+1) {ll t=g[i]*g[d-i]%mod*p1[i]%mod*p2[d-i]%mod*a[i]%mod;if ((d-i)&1) ans=(ans-t+mod)%mod;else ans=(ans+t)%mod;}return ans;}void init(int M) {f[0]=f[1]=g[0]=g[1]=1;rep(i,2,M+5) f[i]=f[i-1]*i%mod;g[M+4]=powmod(f[M+4],mod-2);per(i,1,M+4) g[i]=g[i+1]*(i+1)%mod;}ll polysum(ll n,ll *a,ll m) { // a[0].. a[m] \sum_{i=0}^{n-1} a[i]a[m+1]=calcn(m,a,m+1);rep(i,1,m+2) a[i]=(a[i-1]+a[i])%mod;return calcn(m+1,a,n-1);}ll qpolysum(ll R,ll n,ll *a,ll m) { // a[0].. a[m] \sum_{i=0}^{n-1} a[i]*R^iif (R==1) return polysum(n,a,m);a[m+1]=calcn(m,a,m+1);ll r=powmod(R,mod-2),p3=0,p4=0,c,ans;h[0][0]=0;h[0][1]=1;rep(i,1,m+2) {h[i][0]=(h[i-1][0]+a[i-1])*r%mod;h[i][1]=h[i-1][1]*r%mod;}rep(i,0,m+2) {ll t=g[i]*g[m+1-i]%mod;if (i&1) p3=((p3-h[i][0]*t)%mod+mod)%mod,p4=((p4-h[i][1]*t)%mod+mod)%mod;else p3=(p3+h[i][0]*t)%mod,p4=(p4+h[i][1]*t)%mod;}c=powmod(p4,mod-2)*(mod-p3)%mod;rep(i,0,m+2) h[i][0]=(h[i][0]+h[i][1]*c)%mod;rep(i,0,m+2) C[i]=h[i][0];ans=(calcn(m,C,n)*powmod(R,n)-c)%mod;if (ans<0) ans+=mod;return ans;}
}
ll n,k,R;
ll a[maxn];
int main() {ios::sync_with_stdio(0);cin>>n>>R>>k;for(int i = 0;i<=2010;i++) a[i] = powmod(i,k);polysum::init(k+5);ll ans = 0;ans = polysum::qpolysum(R,n+1,a,k+1);if(k==0) ans = (ans-1+mod)%mod;cout<<ans<<endl;}

不是我说dls也太强了吧,,随便一个namespace全世界都在用。。。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/441413.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

python归并排序 分词_python实现归并排序,归并排序的详细分析

学习归并排序的过程是十分痛苦的。它并不常用&#xff0c;看起来时间复杂度好像是几种排序中最低的&#xff0c;比快排的时间复杂度还要低&#xff0c;但是它的执行速度不是最快的。很多朋友不理解时间复杂度低为什么运行速度不一定快&#xff0c;这个不清楚的伙伴可以看下我之…

CCFCSP 2018年9月 -- 部分题目

CCF201809 -- 第一题 &#xff1a;买菜 问题描述   在一条街上有n个卖菜的商店&#xff0c;按1至n的顺序排成一排&#xff0c;这些商店都卖一种蔬菜。   第一天&#xff0c;每个商店都自己定了一个正整数的价格。店主们希望自己的菜价和其他商店的一致&#xff0c;第二天…

servlet中显示mysql字段_Java Servlet:从数据库获取信息并在屏幕上显示它

创建它代表了表的每一个项目(行)一个JavaBean类。创建一个使用JDBC返回这些项目列表的DAO类。然后在servlet中&#xff0c;只需使用HttpServletRequest#setAttribute()将请求范围中的项目列表&#xff0c;使用RequestDispatcher#forward()将请求转发到JSP文件&#xff0c;并使用…

【CodeForces - 689B】Mike and Shortcuts(Dijkstra最短路,或者bfs跑状态类似spfa)

题干&#xff1a; Recently, Mike was very busy with studying for exams and contests. Now he is going to chill a bit by doing some sight seeing in the city. City consists of n intersections numbered from 1 to n. Mike starts walking from his house located a…

sqlserver mysql分页_SQLServer与MySQL中分页查询sql语句示例

/***author blovedr*功能&#xff1a;SQLServer与MySQL中分页查询sql语句示例*日期&#xff1a; 2018年8月17日 10:58*注释&#xff1a; 学习数据库MySQL的点点记录&#xff0c; 谢谢网上各位大神分享经验与资料&#xff0c; 欢迎大神批评与交流。*/分页查询 2018.8.16 …

【51Nod - 1103】N的倍数 (思维,鸽巢原理也叫抽屉定理,求倍数问题取模)

题干&#xff1a; 一个长度为N的数组A&#xff0c;从A中选出若干个数&#xff0c;使得这些数的和是N的倍数。 例如&#xff1a;N 8&#xff0c;数组A包括&#xff1a;2 5 6 3 18 7 11 19&#xff0c;可以选2 6&#xff0c;因为2 6 8&#xff0c;是8的倍数。 Input 第1行…

java位操作_关于java按位操作运算

<1>.在了解位移之前&#xff0c;先了解一下正数和负数的二进制表示形式以及关系&#xff1a;举例15和-15&#xff1a;15 的原码&#xff1a; 00000000 00000000 00000000 00001111补码&#xff1a; 11111111 11111111 11111111 111100001 -15的原码&#xff1a;11111111 …

【51Nod - 1117 】聪明的木匠 (贪心,哈夫曼树,时光倒流)

题干&#xff1a; 一位老木匠需要将一根长的木棒切成N段。每段的长度分别为L1,L2,......,LN&#xff08;1 < L1,L2,…,LN < 1000&#xff0c;且均为整数&#xff09;个长度单位。我们认为切割时仅在整数点处切且没有木材损失。 木匠发现&#xff0c;每一次切割花费的体…

java生成16位随机数_java中如何产生一个16位数字组成的随机字符串?谢谢各位了...

展开全部方法如下&#xff1a;Random rannew random();boolean flagtrue;while(flag){int aran.nextInt(99999999);int bran.nextInt(99999999);long ca*100000000Lb;if(c>1000000000000000L&&c<9999999999999999L){flagfalse;c1c;String numString.valueOf(c1);…

java utf-8 gbk_Java 字符转码之UTF-8转为GBK/GB2312

java跟python类似的做法&#xff0c;在java中字符串的编码是java修改过的一种Unicode编码&#xff0c;所以看到java中的字符串&#xff0c;心理要默念这个东西是java修改过的一种Unicode编码的编码。packagestring;importjava.nio.charset.Charset;public classUTF82GBK {publi…

【CodeForces - 760B 】Frodo and pillows (二分题意,注意细节)

题干&#xff1a; n hobbits are planning to spend the night at Frodos house. Frodo has n beds standing in a row and m pillows (n ≤ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of cour…

eclipse wsdl2java_使用Eclipse的wsdl2java工具

一、用Eclipse调用Axis的wsdl2java1.在eclipse里面新建一个项目或已有的项目&#xff1b;2.导入activation.jaraxis.jarcommons-discovery.jarcommons-logging-1.0.3.jarjaxrpc.jarsaaj.jarwsdl4j-1.5.2.jar包3右击你的工程&#xff0d;Run As&#xff0d;Run...&#xff0d;右…

【POJ - 2785】4 Values whose Sum is 0 (二分,折半枚举)

题干&#xff1a; The SUM problem can be formulated as follows: given four lists A, B, C, D of integer values, compute how many quadruplet (a, b, c, d ) ∈ A x B x C x D are such that a b c d 0 . In the following, we assume that all lists have the same…

java好的博客_推荐5个万博爆款Java开源博客,是我目前用过最好用的博客系统

1.OneBlog一个简洁美观、功能强大并且自适应的Java博客&#xff0c;使用springboot开发&#xff0c;前端使用Bootstrap&#xff0c;支持移动端自适应&#xff0c;配有完备的前台和后台管理功能。功能简介多种编辑器、自动申请友情链接、百度推送、评论系统、权限管理、SEO、实时…

【UVALive - 3126】Taxi Cab Scheme (二分图,最小路径覆盖)

题目大意&#xff1a; 有n个出车安排&#xff0c;一辆车能接到这个安排的条件是&#xff1a;1、这辆车第一次发车&#xff1b;2、这辆车接了上一个安排&#xff0c;回到这个安排的起点的时间正好是这个安排的前一分钟或者更早 解题报告&#xff1a; 建图然后跑最小路径覆盖。…

java await signal_Java中的await()/signal()用法

二、方法await()/signal()在JDK5.0以后&#xff0c;JAVA提供了新的更加健壮的线程处理机制&#xff0c;包括了同步、锁定、线程池等等&#xff0c;可以实现更小粒度上的控制。await()和signal()就是其中用来同步的两种方法&#xff0c;功能基本上和wait()/notify()相同&#xf…

【HDU - 1083 】Courses (二分图)

题干&#xff1a; Consider a group of N students and P courses. Each student visits zero, one or more than one courses. Your task is to determine whether it is possible to form a committee of exactly P students that satisfies simultaneously the conditions:…

java 主备切换_keepalived 实现 Java 服务的高可用(主备切换)

前言本文要说的是基于 keepalived 实现两台服务器之间的主备切换&#xff0c;从而实现 Java 服务的高可用。keepalived 的原理不多做介绍&#xff0c;自行搜索了解&#xff0c;keepalived 的安装部署请参考 keepalived 的安装及使用 。个人建议不要沉迷于 死扣 和 理解 原理&am…

【HDU - 2444】The Accomodation of Students(二分图判断 + 匈牙利算法求最大匹配)

题干&#xff1a; There are a group of students. Some of them may know each other, while others dont. For example, A and B know each other, B and C know each other. But this may not imply that A and C know each other. Now you are given all pairs of studen…

最长上升子序列 java_最长上升子序列 O(nlogn)解法 (java)

最长递增子序列问题&#xff1a;在一列数中寻找一些数&#xff0c;这些数满足&#xff1a;任意两个数a[i]和a[j]&#xff0c;若i 设dp[i]表示以i为结尾的最长递增子序列的长度&#xff0c;则状态转移方程为&#xff1a; dp[i] max{dp[j]1}, 1<j 这样简单的复杂度为O(n^2)&a…