赞
踩
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define endl "\n"
- #define int long long
- const int N = 3e5 + 10;
- const int mod=1e9+7;
-
- ll fastmi(ll base, ll power)
- {
- ll ans = 1;
- while (power)
- {
- if (power & 1)ans=ans*base%mod;
- base=base*base%mod;
- power >>=1;
- }
- return ans;
- }
-
- void mysolve()
- {
- int n;
- cin>>n;
- int ans=0;
- for(int i=3; i<=2*n-1; ++i)
- ans=(ans+((min(i-1,n)+i/2+1)*(min(i-1,n)-i/2)/2)%mod*fastmi(i,mod-2)%mod)%mod;
- cout<<ans<<endl;
- }
-
- int32_t main()
- {
- std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
- ll t=1;
- //cin >> t;
- while (t--)
- {
- mysolve();
- }
- system("pause");
- return 0;
- }
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define endl "\n"
- #define int long long
- typedef pair<int, int> pii;
- const int N = 2000+20;
-
- int mycnt(int x)
- {
- int ans=0;
- while(x)ans++,x/=10;
- return ans;
- }
- const int mod=1e9+7;
- pii a[N];
- int pre[N],A[N];//pre表示10的几次幂,A是排列数
- void mysolve()
- {
- int n;
- cin>>n;
- for(int i=1; i<=n; ++i)cin>>a[i].first,a[i].second=mycnt(a[i].first);
- int ans=0;
- for(int i=1; i<=n; ++i)
- {
- vector<int>dp(n+1);//讨论当前元素a[i]在所有排列的总贡献,先给他处理下dp
- dp[0]=1;
- for(int j=1,p=0; j<=n; ++j)if(i!=j)//背包优化
- {
- p++;//p表示处理了p个数
- for(int k=p; k; --k)dp[k]=(dp[k]+dp[k-1]*pre[a[j].second]%mod)%mod;
- }
- for(int j=0; j<n; ++j)//枚举ai前面有几个元素的情况时的贡献
- ans=(ans+a[i].first*A[n-j-1]%mod*dp[j]%mod*A[j]%mod)%mod;
- }
- cout<<ans<<endl;
- }
-
- int32_t main()
- {
- std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
- pre[0]=1,A[0]=1;
- for(int i=1; i<=2000; ++i)pre[i]=pre[i-1]*10%mod,A[i]=A[i-1]*i%mod;
- mysolve();
- system("pause");
- return 0;
- }
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define endl "\n"
- const int INF = 0x3f3f3f3f; //int型的INF
- const double eps=1e-9;
- const int N = 3e3 + 10;
-
- vector<int>edge[N];
- int mxans[N],mnans[N],mxdp[N][N],mndp[N][N],sz[N];
- bool a[N];
- int n;
- void dfs(int u,int f)
- {
- sz[u]=1;
- for(auto v:edge[u])if(v!=f)
- {
- dfs(v,u);
- for(int i=sz[u]; ~i; --i)for(int j=sz[v]; j; --j)
- {
- mxdp[u][i+j]=max(mxdp[u][i+j],mxdp[u][i]+mxdp[v][j]+2);
- mndp[u][i+j]=min(mndp[u][i+j],mndp[u][i]+mndp[v][j]+2);
- if(i)
- {
- mxans[i+j]=max(mxans[i+j],mxdp[u][i]+mxdp[v][j]+2);//这里不写mxdp[u][i+j],因为u的i+j是可以由i=0,j>0更新得到,但是子树合并必须ij均大于0合并,才算是最短路径的最大值,否者不符合最短路径的定义
- mnans[i+j]=min(mnans[i+j],mndp[u][i]+mndp[v][j]+2);
- }
- }
- sz[u]+=sz[v];
- }
- }
- void mysolve()
- {
-
- cin>>n;
- for(int i=1; i<=n; ++i)
- {
- mxans[i]=-INF;
- mnans[i]=INF;
- for(int j=1; j<=n; ++j)mxdp[i][j]=-INF,mndp[i][j]=INF;
- }
- for(int i=1; i<=n; ++i)
- {
- cin>>a[i];
- if(a[i])mxdp[i][1]=mndp[i][1]=0,mxans[1]=mnans[1]=0;
- }
- int x,y;
- for(int i=1; i<n; ++i)cin>>x>>y,edge[x].push_back(y),edge[y].push_back(x);
- dfs(1,0);
- for(int i=1; i<=n; ++i)
- {
- if(mxans[i]>=0)cout<<mxans[i]<<" "<<mnans[i]<<endl;
- else
- cout<<-1<<" "<<-1<<endl;
- }
- }
-
- int32_t main()
- {
- std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
- ll t=1;
- //cin >> t;
- while (t--)
- {
- mysolve();
- }
- system("pause");
- return 0;
- }
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define int long long
- typedef pair<int, int> pii;
- const int N = 3e5 + 10,G = 3, Gi = 332748118;
- const int mod=998244353;
-
- vector<pii>pre[15];
- int limit,L;
- int r[N];
- void init()
- {
- pre[3].push_back({4,5+4});
- pre[4].push_back({3,5+3});
- pre[5].push_back({12,13+12});
- pre[6].push_back({8,10+8});
- pre[7].push_back({24,25+24});
- pre[8].push_back({6,10+6});
- pre[8].push_back({15,17+15});
- pre[9].push_back({12,15+12});
- pre[9].push_back({40,41+40});
- pre[10].push_back({24,26+24});
- }
-
- ll fastmi(ll base, ll power)
- {
- ll ans = 1;
- while (power)
- {
- if (power & 1)ans=ans*base%mod;
- base=base*base%mod;
- power >>=1;
- }
- return ans;
- }
-
- inline void NTT(ll *A, int type)
- {
- for(int i = 0; i < limit; i++)
- if(i < r[i]) swap(A[i], A[r[i]]);
- for(int mid = 1; mid < limit; mid <<= 1)
- {
- ll Wn = fastmi( type == 1 ? G : Gi, (mod - 1) / (mid << 1));
- for(int j = 0; j < limit; j += (mid << 1))
- {
- ll w = 1;
- for(int k = 0; k < mid; k++, w = (w * Wn) % mod)
- {
- int x = A[j + k], y = w * A[j + k + mid] % mod;
- A[j + k] = (x + y) % mod,
- A[j + k + mid] = (x - y + mod) % mod;
- }
- }
- }
- }
-
- ll aa[N],bb[N];
- void mysolve()
- {
- vector<int>a1,b1;
- unordered_map<int,int>a,b;
- int n,A,B;
- cin>>n>>A>>B;
- int x1,y1;
- for(int i=1; i<=n; ++i)
- {
- cin>>x1>>y1;
- if(y1==A)a[x1]=1,a1.push_back(x1);
- else b[x1]=1,b1.push_back(x1);
- }
- int ans=0;
- int d=abs(A-B);
- sort(a1.begin(),a1.end()),sort(b1.begin(),b1.end());
-
- for(auto v:a1)//暴力枚举第一种
- {
- for(pii u:pre[d])
- {
- if(b.count(v+u.first)&&b.count(v+u.second))ans++;
- if(b.count(v-u.first)&&b.count(v-u.second))ans++;
- if(b.count(v+u.first)&&b.count(v-(u.second-2*u.first)))ans++;
- if(b.count(v-u.first)&&b.count(v+(u.second-2*u.first)))ans++;
- }
- if(b.count(v+d)&&b.count(v))ans++;
- if(b.count(v-d)&&b.count(v))ans++;
- ans%=mod;
- }
- for(auto v:b1)
- {
- for(pii u:pre[d])
- {
- if(a.count(v+u.first)&&a.count(v+u.second))ans++;
- if(a.count(v-u.first)&&a.count(v-u.second))ans++;
- if(a.count(v+u.first)&&a.count(v-(u.second-2*u.first)))ans++;
- if(a.count(v-u.first)&&a.count(v+(u.second-2*u.first)))ans++;
- }
- if(a.count(v+d)&&a.count(v))ans++;
- if(a.count(v-d)&&a.count(v))ans++;
- ans%=mod;
- }
-
- limit=1,L=0;//NNT计算i+j枚举后各个数的出现次数
- while(limit<=2e5)limit<<=1,L++;
- for(int i = 0; i < limit; i++)
- r[i] = (r[i >> 1] >> 1) | ((i & 1) << (L - 1));
- for(int i=0; i<=1e5; ++i)
- {
- if(a[i])aa[i]=1;
- if(b[i])bb[i]=1;
- }
- NTT(aa,1),NTT(bb,1);
- for(int i=0; i<limit; ++i)aa[i]=aa[i]*aa[i]%mod,bb[i]=bb[i]*bb[i]%mod;//多项式a*a
- NTT(aa,-1),NTT(bb,-1);
- ll inv=fastmi(limit,mod-2);
- for(int i=0; i<=2e5; ++i)aa[i]=aa[i]*inv%mod,bb[i]=bb[i]*inv%mod;
-
- int res=0;
- for(int i=0; i<=1e5; ++i)
- {
- if(a[i])res+=bb[i<<1]-b[i];//减去i+i的情况
- if(b[i])res+=aa[i<<1]-a[i];
- }
- ans=(ans+res/2)%mod;//因为i+j与j+i各自算了一次,要除2
- cout<<ans<<endl;
- }
-
- int32_t main()
- {
- std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
- ll t=1;
- //cin >> t;
- while (t--)
- {
- init();
- mysolve();
- }
- system("pause");
- return 0;
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。