zoukankan      html  css  js  c++  java
  • 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

     

  • 相关阅读:
    leetcode 763. Partition Labels
    JS字符串格式化~欢迎来搂~~
    手把手教你在pycharm上上传项目至GitHub
    手把手教你用原始方式上传项目至GitHub
    python3.7环境下创建app、运行Django1.11版本项目报错Generator expression must be parenthesized
    在学习python的DjangoFlaskTornado前你需要知道的,what is web?
    python手撸桌面计算器
    jQuery之克隆事件--clone()与clone(true)区别
    前端之jQuery基础
    通过案例来剖析JQuery与原生JS
  • 原文地址:https://www.cnblogs.com/qq-1585047819/p/11704006.html
Copyright © 2011-2022 走看看