hdu 5119 Happy Matt Friends

來源:互聯網
上載者:User

標籤:

http://acm.hdu.edu.cn/showproblem.php?pid=5119

題意:有n個數,然後從中挑選任意多的數進行異或,問異或出的值大於等於M的方案數多少?

思路:轉移方程f[i][j]=f[i-1][j]+f[i-1][j^a[i]].  可以枚舉這個值,對每個狀態,來源有兩個——一是上一個階段不取,二是取a[i].

 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #define ll long long 5 #define maxn 50 6 using namespace std; 7  8 int t,n,m; 9 int a[maxn];10 ll dp[50][(1<<20)+10];11 12 int main()13 {14     scanf("%d",&t);15     for(int cas=1; cas<=t; cas++)16     {17         scanf("%d%d",&n,&m);18         memset(dp,0,sizeof(dp));19         for(int i=1; i<=n; i++)20         {21             scanf("%d",&a[i]);22         }23         dp[0][0]=1;24         for(int i=1; i<=n; i++)25         {26             for(int j=0; j<(1<<20); j++)27             {28                 dp[i][j]=dp[i-1][j]+dp[i-1][j^a[i]];29             }30         }31         ll ans=0;32         for(int i=m; i<(1<<20); i++)33         {34             ans+=dp[n][i];35         }36         printf("Case #%d: %lld\n",cas,ans);37     }38     return 0;39 }
View Code

 

hdu 5119 Happy Matt Friends

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.