SPOJ - Cards Problem Solution
Solution:-
using namespace std;
#define MAX 1000010
#define MOD 1000007
int dp[MAX];
int main()
{
for(int i=1;i<=MAX;i++)
dp[i]=(((((i*2)%MOD)+i-1)%MOD)+dp[i-1])%MOD;
int tc;
cin>>tc;
while(tc--)
{
int N;
cin>>N;
cout<<dp[N]<<endl;
}
return 0;
}
No comments:
Post a Comment