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