- #include <bits/stdc++.h>
- using namespace std;
- int a[10], dp[11][11];
- int n, m;
- int calc(int n, int prev){
- if(n == 0){
- return 1;
- }
- if(dp[n][prev]!= -1){
- return dp[n][prev];
- }
- int sum = 0;
- for(int i = 0; i <m; i++){
- if(abs(a[i]-prev)<= 2){
- sum+= calc(n-1, a[i]);
- }
- }
- return dp[n][prev] = sum;
- }
- int main()
- {
- int tc;
- scanf("%d", &tc);
- for (int p = 0; p < tc; ++p) {
- cin>>m>>n;
- for(int i = 0; i <m; i++){
- cin>>a[i];
- }
- memset(dp, -1, sizeof(dp));
- int sum = 0;
- for(int i = 0; i <m; i++){
- sum+= calc(n-1, a[i]);
- }
- cout<<"Case "<<(p+1)<<": "<<sum<<endl;
- }
- return 0;
- }
Thursday 27 July 2017
Lightoj 1122 - Digit Count
Subscribe to:
Post Comments (Atom)
Most Featured Post
Lightoj 1159 - Batman
http://lightoj.com/volume_showproblem.php?problem=1159 problem analysis: First i thought of this as if s1, s2 and s3 are those three str...
-
Problem link: Problem Analysis: It is actually a basic Bisection problem , as we can see here we can not actually find a formula fo...
-
http://lightoj.com/volume_showproblem.php?problem=1382 Problem analysis: This is a rare problem i wrote about so far. After much strugg...
No comments:
Post a Comment