Uva 10404-bachet ' s game (game)

Source: Internet
Author: User

Topic Link: Click to open the link

In the DP topic brush, look like game on the water passed.

Test instructions: N items, two people take turns, the number of each fetch must be a set of S (the set must contain 1) in a number, and finally can not be picked to lose (that is, take away the last item wins).

Idea: recursion. Set W[i] for the status of I items, W[i]=1 represents the initiator win, W[i]=0 represents the initiator will be defeated. You can know w[1]=1, and recursion generates all States.

It can be known that for a state, if his successor will fail, then the state is the winning state, if all subsequent to the state is a winning state, then the state is a must.


#include <algorithm> #include <iostream> #include <cstring> #include <cstdlib> #include < string> #include <cctype> #include <vector> #include <cstdio> #include <cmath> #include < queue> #include <stack> #include <map> #include <set> #define MAXN 1000002#define _ll __int64#define ll long long#define INF 0x3f3f3f3f#define Mod 10000007#define pp pair<int,int> #define ull unsigned long longusing na Mespace std;int N,m,s[12];bool w[maxn];void Solve () {memset (w,0,sizeof (w)); w[1]=1;for (int i=2;i<=n;i++) {w[i]=0; for (int j=0;j<m&&i-s[j]>=0;j++) {if (!w[i-s[j]) {w[i]=1;break;}}} if (W[n]) puts ("Stan wins"), Else puts ("Ollie wins");} int main () {while (~SCANF ("%d", &n)) {scanf ("%d", &m), and for (int i=0;i<m;i++) scanf ("%d", s+i); sort (s,s+m); Solve ();} return 0;}


Uva 10404-bachet ' s game (game)

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.