类似生成树的做法去边权降序的前k或n-1条边
T2
发现这个东西可以转化成上一行的前缀积乘上行号
质因数肯定是小于n的职数 每个数的指数是一个组合数的形式
XJB算一下好了
#include<cstdio> #include<time.h> #include<assert.h> #include<iostream> #define mod 1000000009 using namespace std; int n,k;int g[2333][2333],G[2333][2333]; long long _pow(int a,int n){ if(!n)return 1; long long t=_pow(a,n/2); if(n&1)return t*t*a%mod; else return t*t%mod; } long long ba[2333],li[2333],li2[2333],_li=0; void fenjie(int a,int n){ _li=0; int p=2; while(a>1){ if(!(a%p)){ li[++_li]=p; li2[_li]=0; while(!(a%p)){ ++li2[_li]; a/=p; } } ++p; } for(int i=1;i<=_li;i++){ ba[li[i]]=(ba[li[i]]+li2[i]*n)%mod; } } int main(){ freopen("calc.in","r",stdin); freopen("calc.out","w",stdout); cin>>n>>k; for(int i=0;i<=2332;i++)g[i][1]=i; for(int j=0;j<=2332;j++)g[j][j]=g[j][0]=1; for(int i=2;i<=2332;i++) for(int j=2;j<=2332;j++){ g[i][j]=(g[i-1][j]+g[i-1][j-1])%mod; } for(int i=1;i<=2332;i++){ for(int j=1;j<=2332;j++){ G[i][j]=g[i-1+j-1][i-1]; } } long long t=1; if(k==0){ _li=0;int p=2; while(n>1){ if(!(n%p)){ li[++_li]=p; while(!(n%p)){ n/=p; li2[_li]++; } } p++; } for(int i=1;i<=n;i++){ t=t*(li2[i]+1)%mod; } } if(k>=1){ int i=n,j=k-1; for(int p=i;p>=1;p--){ fenjie(i-p+1,G[p][j+1]); } for(int p=2;p<=2332;p++)t=(t*(long long)(ba[p]+1))%mod; } cout<<t; }
T3
对于单个公司的子图求最短路径长度
然后对于任意两点间所有公司的最短路径长度求一个花费建一个新图
对新图做一个最短路
#include<map> #include<stack> #include<queue> #include<cstdio> #include<string> #include<vector> #include<cstring> #include<complex> #include<iostream> #include<assert.h> #include<algorithm> using namespace std; #define inf 1001001001 #define infll 1001001001001001001LL #define FOR0(i,n) for(int (i)=0;(i)<(n);++(i)) #define FOR1(i,n) for(int (i)=1;(i)<=(n);++(i)) #define ll long long #define dbg(vari) cerr<<#vari<<" = "<<(vari)<<endl #define gmax(a,b) (a)=max((a),(b)) #define gmin(a,b) (a)=min((a),(b)) #define ios0 ios_base::sync_with_stdio(0) #define Ri register int #include<assert.h> #define gc getchar() #define il inline il int read(){ bool f=true; Ri x=0;char ch; while(!isdigit(ch=gc))if(ch==‘-‘)f=false; while(isdigit(ch)){x=(x<<1)+(x<<3)+ch-‘0‘;ch=gc;} return f?x:-x; } #define gi read() #define FO(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout); int n,m,c,s,t; int f[21][101][101]; int g[101][101]; int p[21],q[21][101],r[21][101]; int calc(int c,int len){ int ans=0; for(int i=1;i<=p[c];i++){ if(len>q[c][i]){ ans+=r[c][i]*(q[c][i]-q[c][i-1]); }else{ ans+=r[c][i]*(len-q[c][i-1]); return ans; } } return ans; } int main(){ //FO(railway); memset(f,127/3,sizeof(f)); freopen("railway.in","r",stdin); freopen("railway.out","w",stdout); n=gi;m=gi;c=gi;s=gi;t=gi; FOR1(i,m){ int x,y,z,b; x=gi;y=gi;z=gi;b=gi; f[b][x][y]=f[b][y][x]=z; } FOR1(i,c)p[i]=gi; FOR1(i,c){ FOR1(x,p[i]-1)q[i][x]=gi;q[i][p[i]]=inf; FOR1(x,p[i]) r[i][x]=gi; } FOR1(_,c)FOR1(i,n)f[_][i][i]=0; FOR1(_,c){ FOR1(p,n)FOR1(i,n)FOR1(j,n)gmin(f[_][i][j],f[_][i][p]+f[_][p][j]); } memset(g,127/3,sizeof(g)); FOR1(i,n)g[i][i]=0; FOR1(k,c){ FOR1(i,n){ FOR1(j,n){ //if(f[k][i][j]&&f[k][i][j]<f[0][0][0]){ int T=calc(k,f[k][i][j]); //assert(T>0); gmin(g[i][j],T); gmin(g[j][i],T); //} } } }//puts(""); FOR1(p,n)FOR1(i,n)FOR1(j,n)gmin(g[i][j],g[i][p]+g[p][j]); cout<<g[s][t]; return 0; } /* 4 4 2 1 4 1 2 2 1 2 3 2 1 3 4 5 1 2 4 4 2 3 2 3 6 10 5 3 100 10 9*/
时间: 2024-10-24 21:01:52