标签:
题目链接:
Time Limit: 4000/2000 MS (Java/Others)
Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 323 Accepted Submission(s): 127
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> using namespace std; const long long mod=1e9+7; int t; long long n,k,a[200000]; int main() { scanf("%d",&t); while(t--) { cin>>n>>k; long long x=n/k; if(k*(k+1)/2>n) { printf("-1\n"); } else { if(k%2) { for(int i=k/2;i>0;i--) { a[i]=x-(k/2-i+1); } for(int i=k/2+1;i<=k;i++) { a[i]=x+(i-k/2-1); } int m=n%k; for(int i=k;m>0;m--,i--) { a[i]++; } } else { for(int i=k/2;i>0;i--) { a[i]=x-(k/2-i+1); } for(int i=k/2+1;i<=k;i++) { a[i]=x+(i-k/2); } int m=n%k; for(int i=k/2;i&&m;i--,m--) { a[i]++; } if(m>0) { for(int i=k;i>k/2&&m;i--,m--) { a[i]++; } } } long long ans=a[1]; for(int i=2;i<=k;i++) { ans*=a[i]; ans%=mod; } cout<<ans<<"\n"; } } return 0; }
hdu-5646 DZY Loves Partition(贪心)
标签:
原文地址:http://www.cnblogs.com/zhangchengc919/p/5296626.html