Recursive DP Race Code 1005 game

Source: Internet
Author: User

Topic Portal

1 /*2 Recursive DP: the official puzzle3 If the fi,j represents the remaining I person, if the position of the Brotherk is 1, then whether the position of J is likely to win4 when transferring, you can enumerate the number specified by the current wheel, then you can calculate the position of the current position J in the left i−1 person.5 (assuming the position of Brotherk is 1), and then use the previously calculated F-value to determine if the person is likely to win6 time Complexity of O (N3)7 Dp[i][j] Indicates that there is an I person, whether a person of J position can win.    Dp[1][0] = 1; CNT = SUM (dp[n][i]);8 with the most optimized substructure, I individuals can be one step closer by i-1 individual situations where each can win9 tips for taking the remainder: 0~n-1Ten */ One#include <cstdio> A#include <iostream> -#include <algorithm> -#include <cstring> the#include <string> -#include <map> -#include <vector> -#include <Set> +#include <cmath> -#include <queue> + using namespacestd; A  at Const intMAXN = 2e2 +Ten; - Const intINF =0x3f3f3f3f; - intDP[MAXN][MAXN]; - intS[MAXN]; -  - intMainvoid)//Race Code 1005 game in { -     //freopen ("e.in", "R", stdin); to  +     intt, N, M; -scanf ("%d", &t); the      while(t--) *     { $scanf ("%d%d", &n, &m);Panax Notoginseng          for(intI=1; i<=m; ++i) -         { thescanf ("%d", &s[i]); +         } AMemset (DP,0,sizeof(DP)); thedp[1][0] =1; +  -          for(intI=2; i<=n; ++i) $         { $              for(intj=0; j<n; ++j) -             { -                 if(dp[i-1][j]) the                 { -                      for(intk=1; k<=m; ++k)Wuyi                     { thedp[i][(j + s[k])% i] =1; -                     } Wu                 } -             } About         } $  -         intCNT =0; -          for(intI=0; i<n; ++i)if(Dp[n][i]) cnt++; -  Aprintf ("%d\n", CNT);intx =0; +          for(intI=0; i<n; ++i) the         { -             if(Dp[n][i]) $             { theprintf ("%d", i +1); ++x; the                 if(x < CNT) printf (" "); the             } the         } -Puts (""); in     } the  the     return 0; About}

Recursive DP Race Code 1005 game

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.