great God with three little partnersTime limit: 2000ms single point time limit: 1000ms memory limit: 256MB
Description
L Country is a beautiful scenery and rich country, many people like to travel here and like to take away some souvenirs, big God classmate is no exception. Distance open the time of the L country more and more near, the big God schoolmate is worrying to her lovable small partner to bring what souvenir good, now put in the big God schoolmate to have three kinds of souvenirs A, B, C can choose, each kind of souvenir has n kinds. The types of a_i, b_i, c_i souvenir value are all I, and there are n+1-i surplus. Now the great God students want to choose one of the three categories of souvenirs and then presented to her three lovely small partners, but she didn't want to pick out two souvenirs of the same value, because the two small partners who received the same value souvenirs would think that the students of the great God had been biased towards another small partner for more than a week. Now, the great god students want you to buy three pieces of souvenirs to make three small partners happy and not uncomfortable with her, she would like to know how many different choice of methods.
Because the number of programs can be very large, the great God students want to know the choice of souvenirs 10^9+7 the answer after the model.
input
The first line consists of a number of T, representing the number of groups of data.
Next contains the T-group data, one row for each set of data, including an integer n.
Output
For each set of data, the output line "case x:", where x indicates the number of each group of data (starting from 1), followed by a number, which represents the number of options for 10^9+7 after the die.
Data Range
Small Data:
1<=t<=10
1<=n<=100
Large data:
1<=t<=1000
1<=n<=10^18
Sample Explanation
For the second set of data, the legal scheme has the following, (X,y,z) to select a category A souvenir value of X, Category B souvenirs in the value of Y, C-Class souvenirs in the value of Z.
(1,1,1): 3*3*3=27 species
(1,2,3): 3*2*1=6 species
(1,3,2): 3*1*2=6 species
(2,1,3): 2*3*1=6 species
(2,2,2): 2*2*2=8 species
(2,3,1): 2*1*3=6 species
(3,1,2): 1*3*2=6 species
(3,2,1): 1*2*3=6 species
(3,3,3): 1*1*1=1 species
A total of 27+6+6+6+8+6+6+6+1=72 options for souvenir selection
Note that, for example (1,1,2), (2,3,3), (3,1,3) is not a suitable souvenir selection method because it chooses exactly two items of the same value.
==========================================================================================================
My solution
#include "stdafx.h"
#include <iostream>
#include <math.h>
using namespace std;
int T;
Long Long N;
#define MAXT
Long Long sum[maxt];
Long Long Compute (int x,int y,int z)
{
return ((n+1-x) * (n+1-y) * (n+1-z));
}
int main (int argc, char** argv)
{
cin>>t;
int t=t;
int casenum=0;
for (int i=0;i<=t;i++)
sum[i]=0;
while (t--)
{
Cin>>n;
for (int i=1;i<=n;i++)
{to (int j=1;j<=n;j++)
for (int k=1;k<=n;k++)
{
if ((i!=j) && (j!= k) && (i!=k))
{
Long long val=compute (i,j,k);
Sum[casenum]+=val;
}
}
}
for (int i=1;i<=n;i++)
{
Long long val=compute (i,i,i);
Sum[casenum]+=val;
}
casenum++;
}
for (int i=1;i<=t;i++)
{
printf (' Case%d: ', i);
Long Long A=pow (10.0,9.0) +7;
cout<<sum[i-1]%a<<endl;
}
System ("pause");
return 0;
}
After running small data AC, large data is not passed because the algorithm is not simple enough, time exceeds the limit.