• 2616: Cow Frisbee Team(01背包)


    2616: Cow Frisbee Team 分享至QQ空间

    时间限制(普通/Java):1000MS/10000MS     内存限制:65536KByte
    总提交: 43            测试通过:17

    描述

     

    After Farmer Don took up Frisbee, Farmer John wanted to join in the fun. He wants to form a Frisbee team from his N cows (1 ≤ N ≤ 2,000) conveniently numbered 1..N. The cows have been practicing flipping the discs around, and each cow i has a rating R_i (1 ≤ R_i ≤ 100,000) denoting her skill playing Frisbee. FJ can form a team by choosing one or more of his cows.

    However, because FJ needs to be very selective when forming Frisbee teams, he has added an additional constraint. Since his favorite number is F(1 ≤ F ≤ 1,000), he will only accept a team if the sum of the ratings of each cow in the team is exactly divisible by F.

    Help FJ find out how many different teams he can choose. Since this number can be very large, output the answer modulo 100,000,000.

    Note: about 50% of the test data will have N ≤ 19.

    输入

     

    * Line 1: Two space-separated integers: N and F 
    * Lines 2..N+1: Line i+1 contains a single integer: R_i

    输出

     

    * Line 1: A single integer representing the number of teams FJ can choose, modulo 100,000,000.

    样例输入

     

    4 5
    1
    2
    8
    2

    样例输出

     3

    题目来源

     1 #include <iostream>
     2 #include <cstring>
     3 #include <cstdio>
     4 #include <algorithm>
     5 #define ll long long
     6 using namespace std;
     7 
     8 int n,m;
     9 const ll mod=1e8;
    10 const int maxn=2e3+5;
    11 ll dp[maxn][maxn];    //状态表示 前i件物品于是为j的方案书
    12 int arr[maxn];
    13 
    14 int main(){
    15     ios::sync_with_stdio(false);
    16     cin>>n>>m;
    17     for(int i=1;i<=n;i++){
    18         cin>>arr[i];
    19         arr[i]%=m;
    20         dp[i][arr[i]%m]=1;   //初始化
    21     }
    22     for(int i=1;i<=n;i++){
    23         for(int j=0;j<m;j++){
    24             dp[i][j]=(dp[i][j]%mod+dp[i-1][j]%mod+dp[i-1][(j-arr[i]+m)%m]%mod)%mod;
    25         }
    26     }
    27     cout << dp[n][0] << endl;
    28     return 0;
    29 
    30 }
    View Code

     

  • 相关阅读:
    查看Oracle连接数 限制某个用户的连接数
    (原创网上办法经过改良)系统重装后,如何快速的回复oracle 10g(测试环境:windows server 2003 sp1+Oracle 10g)
    Response.Redirect报"正在中止进程"异常的处理
    快速使网页变灰色
    .NET创建Windows服务[转]
    [收集]javascript中得到当前窗口的高和宽
    [转帖]javascript版 UrlEncode和UrlDecode函数
    js异步读取xml(支持ff和xpath)
    辞职考研后记
    BCB6 E2494 Unrecognized __declspec modifier
  • 原文地址:https://www.cnblogs.com/qq-1585047819/p/11704006.html
Copyright © 2020-2023  润新知