标签:多个 limit strong memset cos using ini div code
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 177 Accepted Submission(s):
133
#include <iostream> #include <algorithm> #include <cstring> #include <cstdio> #include <vector> #include <queue> #include <cstdlib> #include <iomanip> #include <cmath> #include <cassert> #include <ctime> #include <map> #include <set> using namespace std; #define lowbit(x) (x&(-x)) #define max(x,y) (x>y?x:y) #define min(x,y) (x<y?x:y) #define MAX 100000000000000000 #define MOD 1000000007 #define pi acos(-1.0) #define ei exp(1) #define PI 3.141592653589793238462 #define ios() ios::sync_with_stdio(false) #define INF 1044266558 #define mem(a) (memset(a,0,sizeof(a))) typedef long long ll; ll dp[1001][1001]; ll n,m,t; void init() { memset(dp,0,sizeof(dp)); for(int i=1;i<=1000;i++) { dp[i][0]=dp[i][i]=1; for(int j=1;j<i;j++) { dp[i][j]=(dp[i-1][j-1]+dp[i-1][j])%MOD; } } } int main() { init(); scanf("%lld",&t); while(t--) { scanf("%lld%lld",&n,&m); if(n<m) swap(n,m); printf("%lld\n",dp[n][m]); } return 0; }
也可以费马小定理求逆元
#include <iostream> #include <algorithm> #include <cstring> #include <cstdio> #include <vector> #include <queue> #include <cstdlib> #include <iomanip> #include <cmath> #include <cassert> #include <ctime> #include <map> #include <set> using namespace std; #define lowbit(x) (x&(-x)) #define max(x,y) (x>y?x:y) #define min(x,y) (x<y?x:y) #define MAX 100000000000000000 #define MOD 1000000007 #define pi acos(-1.0) #define ei exp(1) #define PI 3.141592653589793238462 #define ios() ios::sync_with_stdio(false) #define INF 1044266558 #define mem(a) (memset(a,0,sizeof(a))) typedef long long ll; ll dp[1001][1001]; ll n,m,t; ll quick_pow(ll x,ll y) { ll ans=1; while(y) { if(y&1) ans=ans*x%MOD; y>>=1; x=x*x%MOD; } return ans; } ll C(int n,int m) { ll ans=1; for(int i=0;i<m;i++) { ans=(ans*(n-i)%MOD)*quick_pow(i+1,MOD-2)%MOD; } return ans; } int main() { scanf("%lld",&t); while(t--) { scanf("%lld%lld",&n,&m); if(n<m) swap(n,m); printf("%lld\n",C(n,m)); } return 0; }
标签:多个 limit strong memset cos using ini div code
原文地址:http://www.cnblogs.com/shinianhuanniyijuhaojiubujian/p/7355789.html