http://acm.hdu.edu.cn/showproblem.php?pid=5139
思路:这道题要先找规律,f(n)=n!*(n-1)!*(n-2)!.....1!; 不能直接打表,而是离线处理,一次性处理出来。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <cstdio> 2 #include <cstring> 3 #include <map> 4 #include <algorithm> 5 #define ll long long 6 #define mod 1000000007 7 #define N 100010 8 using namespace std; 9 10 ll n; 11 struct node 12 { 13 ll c,id,m; 14 bool operator <(const node &a)const 15 { 16 return id<a.id; 17 } 18 }p[N]; 19 bool cmp1(node a,node b) 20 { 21 return a.c<b.c; 22 } 23 24 int main() 25 { 26 int t1=0; 27 while(scanf("%lld",&n)!=EOF) 28 { 29 p[t1].c=n; 30 p[t1].id=t1; 31 t1++; 32 } 33 sort(p,p+t1,cmp1); 34 ll s=1; 35 ll ans=1; 36 int cnt=0; 37 for(int x=1; x<=p[t1-1].c; x++) 38 { 39 s=s*x%mod; 40 ans=ans*s%mod; 41 while(cnt<t1&&p[cnt].c==x) 42 { 43 p[cnt].m=ans; 44 cnt++; 45 } 46 } 47 sort(p,p+t1); 48 for(int i=0; i<t1; i++) 49 { 50 printf("%lld ",p[i].m); 51 } 52 return 0; 53 }