题目链接:
T3:Problem 3 趣味运动会 (sport.cpp)
思路:
T1:打表找规律
T2:暴力
T3:状压dp
代码:
T1:
#include <iostream> #include <algorithm> #include <queue> #include <cstdio> #include <cstring> using namespace std; typedef long long LL; LL maxn; LL ksm(LL x,LL y) { LL z=1; while(y) { if(y&1)z*=x; y>>=1; x*=x; } return z; }/* template<typename T>inline void read(T &x) { x=0; char ch=getchar(); T f=1; while(!isdigit(ch)) { if(ch=='-')f=-1; ch=getchar(); } while(isdigit(ch))x=x*10+ch-'0',ch=getchar(); x=x*f; }*/ void write(LL x) { if(x<0) { putchar('-'); write(-x); } else { if(x/10) write(x/10); putchar(x%10+'0'); } } int main() { // freopen("diy.in","r",stdin); // freopen("diy.out","w",stdout); int T; scanf("%d",&T); while(T--) { LL N; maxn=0; scanf("%lld",&N); if(N%3==0) { printf("%lld\n",ksm(N/3,3)); continue; } else { for(int i=3; i<=10; i++) { for(int j=3; j<=10; j++) { if(N%i==0 && N%j==0 && N%(N-(N/i+N/j))==0) { maxn=max(maxn,(N/i)*(N/j)*(N-(N/i+N/j))); } } } if(!maxn) puts("-1"); else { write(maxn); puts(""); } } } return 0; }