Writing Code(DP)

Power Automate实战:用SharePoint REST API批量处理列表数据(附JSON解析技巧) 本文深入探讨了如何利用Power Automate调用SharePoint REST API实现列表数据的批量自动化处理。文章详细解析了API的协同工作原理、高效的数据获取与筛选技巧,并重点分享了JSON数据解析的核心难点与实战解决方案,旨在帮助企业用户构建稳定可靠的数据处理流程,提升运营效率。 阅读详情

Programmers working on a large project have just received a task to write exactly m lines of code. There are n programmers working on a project, the i-th of them makes exactly ai bugs in every line of code that he writes.

Let’s call a sequence of non-negative integers v1, v2, …, vn a plan, if v1 + v2 + … + vn = m. The programmers follow the plan like that: in the beginning the first programmer writes the first v1 lines of the given task, then the second programmer writes v2 more lines of the given task, and so on. In the end, the last programmer writes the remaining lines of the code. Let’s call a plan good, if all the written lines of the task contain at most b bugs in total.

Your task is to determine how many distinct good plans are there. As the number of plans can be large, print the remainder of this number modulo given positive integer mod.

Input
The first line contains four integers n, m, b, mod (1 ≤ n, m ≤ 500, 0 ≤ b ≤ 500; 1 ≤ mod ≤ 109 + 7) — the number of programmers, the number of lines of code in the task, the maximum total number of bugs respectively and the modulo you should use when printing the answer.

The next line contains n space-separated integers a1, a2, …, an (0 ≤ ai ≤ 500) — the number of bugs per line for each programmer.

Output
Print a single integer — the answer to the problem modulo mod.

Sample test(s)
input
3 3 3 100
1 1 1
output
10
input
3 6 5 1000000007
1 2 3
output
0
input
3 5 6 11
1 2 1
output
0

n个人,m行代码,最多有b个错误,每个人写一行有a[i]个bug,问满足的分配方案的个数。

写了三遍总算是会了(……),dp[i][j][k],前i个人,写了j行,小于等于k个bug的方案数。
然后转移方程就是
dp[i][j][k] = dp[i - 1][j][k] + dp[i][j - 1][k - a[i]];
意思就是这个状态是由第i个人不写第j行和写第j行转移过来。
此时发现第一维可以省略掉(不开这个空间)

#include<cstdio>
#include<cstring>
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int maxn = 1005;
int dp[505][505];
int a[505];
int main()
{
    #ifdef LOCAL
    freopen("C:\\Users\\巍巍\\Desktop\\in.txt","r",stdin);
    //freopen("C:\\Users\\巍巍\\Desktop\\out.txt","w",stdout);
    #endif // LOCAL
    int n,m,b,mod;
    scanf("%d%d%d%d",&n,&m,&b,&mod);
    for(int i = 1;i <= n;i++)
        scanf("%d",&a[i]);
    memset(dp,0,sizeof(dp));
    for(int i = 0;i <= b;i++)
        dp[0][i] = 1;
    for(int i = 1;i <= n;i++)
    {
        for(int j = 1;j <= m;j++)
        {
            for(int k = 0;k <= b;k++)
            {
                if(k < a[i])dp[j][k] = dp[j][k];
                else
                    dp[j][k] = (dp[j][k] + dp[j - 1][k - a[i]])%mod;
            }
        }
    }
    printf("%d\n",dp[m][b]);
    return 0;
}
TMS_WebGMaps_1.9.8.0_Full_Source TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder 立即下载

相关推荐

从外包到转正:一个华为OD亲历者的真实工作体验与避坑指南

本文分享了一位华为OD员工从外包到转正的真实经历与实用建议。通过详细解析华为OD的日常工作、转正核心指标、机试备考技巧及职场突围策略,为读者提供了一份全面的避坑指南。特别针对机试E卷的高频考点和刷题方法,给出了具体的数据分析和实战经验。

weixin_33686714的博客 702

Writing Code(详细)

思路 代码 #include <iostream> #include <algorithm> using namespace std; const int N=1010; int n,m,b,mod; long long sum; long long f[N][N],a[N]; int i,j,k; int main() { cin>>n>...

萌新的博客 603

避坑指南:RFSoC数据转换器多片同步配置的7个致命错误

本文深入剖析了在配置RFSoC多片同步功能时,工程师最常遇到的七个致命错误。从Tile 0的强制启用、时钟域与SYSREF时序,到跨代器件兼容性、电源序列以及动态重配置的陷阱,文章结合实战经验,提供了从原理到调试的完整RF数据转换器配置指南,旨在帮助开发者高效构建相位一致的大规模射频采样系统。

weixin_28452161的博客 533

[Codeforces 543A] Writing Code (完全背包DP)

Codeforces - 543A NN 个人写共计 MM 行代码,第 ii 个人每写一行代码就有 aia_i 个bug 问使得 MM 行代码都被写完,并且总 bug不超过 BB 的方案数 背包DP…… 太久没写了已经不会写了…… dp[n][m][b]表示当前为第 n个人,还剩 m行代码,b个可容许bug 然后无须枚举当前人写了几行代码,只需要从大到小枚举 m 然后把状态还是更新第

MisDeer's blog 388

别再硬编码了!Flowable工作流动态审批人配置全解析(Spring Boot集成版)

本文深入解析Flowable工作流在Spring Boot中的动态审批人配置技术,通过角色、部门等变量实现审批流程的灵活设计。文章详细介绍了架构原理、前端配置映射、动态候选组解析及查询优化方案,帮助企业提升审批流程的适应性和维护效率。

weixin_30919571的博客 136

告别密码本!用Windows NPS给华为/华三交换机做Radius认证,SSH登录更安全

本文详细介绍了如何利用Windows NPS实现华为/华三交换机的Radius认证,提升SSH登录安全性。通过集中化管理、精细化控制和完整审计追踪,企业可告别传统密码本,大幅提升网络设备管理效率。文章包含NPS服务部署指南、交换机配置详解及调试技巧,助力企业构建安全高效的统一认证体系。

weixin_42549723的博客 419

Writing Code(dp)

A. Writing Code time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Programmers working on a large project have just re...

weixin_34416754的博客 191

CMOS sensor 基础

NA

m0_72053187的博客 1659

[CodeForces 543A]Writing Code[DP]

题目链接:[CodeForces 543A]Writing Code[DP] 题意分析: n个程序员合作写m行代码,第i个程序员每次写一行会产生a[i]个bug,程序员顺序工作,1工作之后2工作,如此类推,现在要求总bug数不得超过b。问:写完m行代码,总bug数不超过b的方案有多少种? 解题思路: 首先我们试着定义一个状态,由于程序员顺序工作,那么我们定义dp[i][j]为写了i行代码,

闲停 712

三相逆变器拓扑结构的分析及应用场景

三相逆变器是电力电子领域中广泛应用的一种设备,用于将直流电转换为交流电。不同的拓扑结构在性能、成本、复杂度和应用领域上存在差异。小编将在本文中将进一步拓展对三相逆变器拓扑结构的分析,并探讨其适用的应用场景。

道合顺的博客 2236

[Dify实战] 招投标标书智能生成:模板套用 + 风险校验

摘要:本文提出基于Dify构建AI标书生成工作流,解决传统标书撰写中内容重复(80%复用率)、人工修改效率低、风险检查易出错等痛点。方案包含三大核心模块:1)智能生成(基于模板自动填充项目信息);2)风险校验(AI自动检查废标风险点);3)多角色协作。通过拆分标书结构、设置详细Prompt、建立风险检查清单,实现从"人工撰写"到"参数化自动生成+AI审核"的转型,最终输出标准格式文档并支持企业系统集成。典型应用场景下,系统能自动生成技术方案并识别关键风险(如支付安全合

技术小甜甜:传播可落地技术,帮助个人和企业降低解决真实场景问题的成本 828

Codeforces Round #302 (Div. 2)C (完全背包)

C. Writing Code time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Programmers working on a large project have

u013268685的专栏(有一种幸福叫AC,有一种期待叫AK) 1186

【RTD】AD7793两线式铂电阻PT100/PT1000应用

两线式RTD是低成本的检测方案,适用于检测精度不高、导线长度较短的场合。

只要思想不滑坡,想法总比问题多。 4258

DP与朴素算法差异 【CF】Writing Code

Writing Code time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Programmers working on a large project have just received a task to ...

SummerDream 251

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

Codeforces 543A. Writing Code DP

A. Writing Code time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Programmers working on a large project have

码代码的猿猿 1289

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

Writing Code - CodeForces 543 A dp

Writing Code time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Programmers working on a large project have ju

提比的强行AC 721

CodeForces 543A - Writing Code DP 完全背包

有n个程序,这n个程序运作产生m行代码,但是每个程序产生的BUG总和不能超过b, 给出每个程序产生的代码,每行会产生ai个BUG,问在总BUG不超过b的情况下, 我们有几种选择方法思路:看懂了题意之后就是一个完全背包题了 定义dp[ i ][ j ][ k ] 表示前 i 个程序员,已经写了 j 行代码, 已经产生了 k 个 bugs 。 根据题意,得知第 i 个程序员会写 r 行代码,...

weixin_30748995的博客 190

Codeforces 543A Writing Code 【滚动数组优化dp】

A. Writing Code time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Programmers working on a large project have

世界很大 596

codeforces 543A Writing Code (dp)

一开始想到的dp: f [ i ][ j ][ k ]表示前i个人打了j行有k个错误的方案数,那么转移方程为:f [ i ][ j ][ k ]=f [ i-1][ j-h ][ k-a[i]*h ] (0 很明显超时+MLE。 这时会发现转移只与f [ i-1 ]有关,可以通过降一维来优化,删去第一维。 f [ j ][ k ]=f [ j ][ k ]+f [ j-1 ][ k-a[i]

KatnissJ的博客 816

Codeforces 543 A Writing Code 计数DP

http://codeforces.com/problemset/problem/543/A 题目大意:n个人,一共要写m行程序,每个程序员每行出现的bug数为ai,要求整个程序出现的bug数不超过b的方案数. 题目分析:简单的计数DP,01背包变形。需要记录的是写到第i行时错误的bug数为j的方案。所以定义二维数组dp[i][j]。转移与01背包类似。具体见代码;初始化d

WKLL_ 1015

codefroces 543A Writing Code dp优化 完全背包

Programmers working on a large project have just received a task to write exactly m lines of code. There are n programmers working on a project, the i-th of them makes exactly ai bugs in every line of

黑码 556

CodeForces 543A Writing Code(dp)

题意:告诉你每个程序员写一行代码会产生多少bug,问你n个程序员写m行代码 bug数不超过b的分派方案有多少个。 一开始想到的状态就是dp[i][j][k]表示前i个程序员写了j行代码,bug 不超过k的方案,发现转移是三方的,其实这个状态时刻一改变一下的, 因为最后的程序员可以写,也可以不写,不管写了几行,所以状态转移就只 需要看最后的那个程序员是否写了就行,另外可以滚动数组。 dp[i][j][

只玩三国的程序猿的专栏 536

cf#302 C. Writing Code dp

点击打开链接 题意:有n个程序员,第i个程序员每行会有ai个bug,然后让你按着顺序安排程序员,问你有多少种安排方法,可以使得写m行的bug最多b个 思路: dp[i][j]表示写i行bug数有j个的方法数 转移方程和背包问题类似  最后扫一遍统计一下就好 代码: #include using namespace std; const int maxn =

yxg_123的博客 249

CodeForces 543A Writing Code(DP)

题目链接:http://codeforces.com/problemset/problem/543/A 题意:安排n个人写m行代码,每人每行会出现a[i]个bug,问最多出现k个bug的方案数 思路:令dp(i, j, k)表示前i个人写j行代码未超过k个的方案数,然后就可以类似背包进行转移并降掉一维的空间复杂度 #include <cstdio> #i...

Tongqi 644

Codeforces Round #302 (Div. 1) 543A Writing Code(dp)

A. Writing Code time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Programmers working on a large project have

GKHack's Blog 1072

背包DP || Codeforces 544C Writing Code

程序员写bug的故事23333 题意:n个程序员,一共写m行程序,最多产生b个bug,问方案数 思路:f[i][j]表示写了i行,产生了j个bug的方案数,因为每个人都是可以独立的,所以i循环到n都做一遍 f[i][j] += f[i-1][j-a[i]] 在前一行 i 的 a[i] 个bug还没有写上去的情况数 #include <iostream> #include ...

weixin_30390075的博客 107
上一篇: cf599D Spongebob and Squares(推公式,枚举)
下一篇: Maximum Absurdity(dp)
Techay
博客等级 码龄11年 11粉丝 174原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值