UPC第44场

UPC第44场

D: Landscaping

Farmer John is building a nicely-landscaped garden, and needs to move a large amount of dirt in the process.

The garden consists of a sequence of N flowerbeds (1 <= N <= 100), where flowerbed i initially contains A_i units of dirt. Farmer John would like to re-landscape the garden so that each flowerbed i instead contains B_i units of dirt. The A_i’s and B_i’s are all integers in the range 0…10.

To landscape the garden, Farmer John has several options: he can purchase one unit of dirt and place it in a flowerbed of his choice for $X. He can remove one unit of dirt from a flowerbed of his choice and have it shipped away for $Y. He can also transport one unit of dirt from flowerbed i to flowerbed j at a cost of $Z times |i-j|. Please compute the minimum total cost for Farmer John to complete his landscaping project.

Farmer John 打算修建一座花园,他需要移动不少泥土。

花园由 N 个花坛组成(1<=N<=100),其中花坛 i包含 A_i单位的泥土。FJ 希望花坛 i包含 B_i单位的泥土,

为了达到这个目标,他可以做这几件事情:

  • 购买一单位的泥土,放在指定的花坛中,费用为 X。
  • 从任意一个花坛中移走一单位泥土,费用为 Y。
  • 从花坛 i 运送一单位泥土到花坛 j,费用为 Z[i-j]。

请你帮 FJ 计算移动泥土的最小开销。

输入

* Line 1: Space-separated integers N, X, Y, and Z (0 <= X, Y, Z <= 1000).

* Lines 2…1+N: Line i+1 contains the space-separated integers A_i and B_i.

输出

* Line 1: A single integer giving the minimum cost for Farmer John’s landscaping project.

样例输入

4 100 200 1
1 4
2 3
3 2
4 0

样例输出

210

DP题,USACO的题解给的很巧,把这个题通过一些手段变成了编辑字符问题。以样列为例,我们可以把a数组变成 a 1 a^1 a1:1 2 2 3 3 3 4 4 4 4,目标数组b{4,3,2,0}可以变为: b 1 b^1 b1:1 1 1 1 2 2 2 3 3,问题变成了 a 1 − > b 1 a^1 ->b^1 a1>b1的问题。我们可以定义 f [ i ] [ j ] f[i][j] f[i][j]为a的前i位变成b的前j位的操作数(用i个泥土构造j个泥土), f [ i ] [ j ] 显 然 可 以 由 f [ i − 1 ] [ j ] , f [ i ] [ j − 1 ] , f [ i − 1 ] [ j − 1 ] f[i][j]显然可以由f[i-1][j],f[i][j-1],f[i-1][j-1] f[i][j]f[i1][j],f[i][j1],f[i1][j1]变来。

  1. f [ i − 1 ] [ j ] f[i-1][j] f[i1][j]推得:说白了就是把第i个废了,满足i-1个就能凑出来j个
  2. f [ i ] [ j − 1 ] f[i][j-1] f[i][j1] 推得:后面加上第j个,or理解为把b数组第j个废掉。
  3. f [ i − 1 ] [ j − 1 ] f[i-1][j-1] f[i1][j1] 推得:在已满足状态下花费 z*(a[i]-b[j]) 费用把一份泥土转移即可.

状态转移方程也就是: f [ i ] [ j ] = m i n ( m i n ( f [ i − 1 ] [ j ] + y , f [ i ] [ j − 1 ] + x ) , f [ i − 1 ] [ j − 1 ] + z ∗ a b s ( a [ i ] − b [ j ] ) ) ; f[i][j]=min(min(f[i-1][j]+y,f[i][j-1]+x),f[i-1][j-1]+z*abs(a[i]-b[j])); f[i][j]=min(min(f[i1][j]+y,f[i][j1]+x),f[i1][j1]+zabs(a[i]b[j]));

c o d e : code: code:

#include<iostream>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<cstdio>
#include <vector>
#include <set>
#include<algorithm>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=4500,mod = 998244353;
int a[maxn],b[maxn],la,lb,f[maxn][maxn];
int n,m,ans=0x3f3f3f3f,x,y,z,xx,yy;
int main()
{
    cin >> n >> x >> y >>z;
    for(int i=1;i<=n;i++)
    {
        cin >> xx >> yy;
        while(xx)
        {
            a[++la]=i;
            xx--;
        }
        while(yy)
        {
            b[++lb]=i;
            yy--;
        }
    }
    for(int i=1;i<=la;i++)
    {
        f[i][0]=i*y;
    }
    for(int j=1;j<=lb;j++)
    {
        f[0][j]=x*j;
    }
    for(int i=1;i<=la;i++)
    {
        for(int j=1;j<=lb;j++)
        {
            f[i][j]=min(min(f[i-1][j]+y,f[i][j-1]+x),f[i-1][j-1]+z*abs(a[i]-b[j]));
        }
    }
    cout << f[la][lb];
    return 0;
}

E: Multiple of 2019

Given is a string S consisting of digits from 1 through 9.
Find the number of pairs of integers (i,j) (1≤i≤j≤|S|) that satisfy the following condition:

Condition: In base ten, the i-th through j-th characters of S form an integer that is a multiple of 2019.

给你一个字符串,要你找到一些子区间使得s[l,r]的在十进制下的值 mod 2019 = 0,现在问你有多少这样的子区间。

Constraints
·1≤|S|≤200000
·S is a string consisting of digits from 1 through 9.

输入

Input is given from Standard Input in the following format:

S

输出

Print the number of pairs of integers (i,j) (1≤i≤j≤|S|) that satisfy the condition.

样例输入

【样例1】
1817181712114
【样例2】
14282668646
【样例3】
2119

样例输出

【样例1】
3
【样例2】
2
【样例3】
0

老问题了, s [ l , r ] s[l,r]%p=0 s[l,r] %p=0 s[l,n]%p==s[r,n]%p,如果我们需要找到同余下相同的数。并且是s[l,n]找s[r,n],其中r >= l,所以我们可以从后面往前面求。

c o d e : code: code:

#include<iostream>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<cstdio>
#include <vector>
#include <set>
#include<algorithm>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=100005,mod = 998244353;
map<int,int>mp;
int main()
{
    string s;
    cin >> s;
    int ans=0,sum=0;
    mp[0]=1;
    int k=1;
    for(int i=s.length()-1;i>=0;i--)
    {
        ans=(ans+(s[i]-'0')*k)%2019;
        sum+=mp[ans]++;
        k=k*10%2019;
    }
    cout << sum << endl;
}

K: Cows in a Skyscraper

A little known fact about Bessie and friends is that they love stair climbing races. A better known fact is that cows really don’t like going down stairs. So after the cows finish racing to the top of their favorite skyscraper, they had a problem. Refusing to climb back down using the stairs, the cows are forced to use the elevator in order to get back to the ground floor.

The elevator has a maximum weight capacity of W (1 <= W <= 100,000,000) pounds and cow i weighs C_i (1 <= C_i <= W) pounds. Please help Bessie figure out how to get all the N (1 <= N <= 18) of the cows to the ground floor using the least number of elevator rides. The sum of the weights of the cows on each elevator ride must be no larger than W.

给出n个物品,体积为w[i],现把其分成若干组,要求每组总体积<=W,问最小分组。(n<=18)

输入

* Line 1: N and W separated by a space.
* Lines 2…1+N: Line i+1 contains the integer C_i, giving the weight of one of the cows.

输出

* Line 1: A single integer, R, indicating the minimum number of elevator rides needed.
* Lines 2…1+R: Each line describes the set of cows taking one of the R trips down the elevator. Each line starts with an integer giving the number of cows in the set, followed by the indices of the individual cows in the set.

样例输入

4 10
5
6
3
7

样例输出

3
2 1 3
1 2
1 4

应该是状压DP裸题,但是吧,我并不会。考虑dfs爆搜,由于N<=18,所以直接枚举电梯数去dfs判断可行即可,至于怎末存储具体分组,看代码。

c o d e : code: code:

#include<iostream>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<cstdio>
#include <vector>
#include <set>
#include<algorithm>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=45,mod = 998244353;
int  c[maxn];
int n,m,ans=0x3f3f3f3f;
struct node  // l存每个组的大小,a1数组存这个组有哪些,sum存这组的重量
{
    int l=0;
    int a1[maxn];
    int sum=0;
}v[maxn];
int dfs(int x,int num) // x表示第x个物品,num表示分组数
{
    for(int i=1;i<=x&&i<=num;i++) //枚举所有组。
    {
        if(v[i].sum+c[x]<=m) //这组可以放下
        {
            v[i].l++;
            v[i].a1[v[i].l]=x;
            v[i].sum+=c[x];
            if(x==n) return 1;
            if(dfs(x+1,num)) return 1;
             v[i].l--; //回溯
            v[i].sum-=c[x];
        }
    }
    return 0;
}
int main()
{
    cin >> n >> m;
    for(int i=1;i<=n;i++)
    {
        cin >> c[i];
    }
    int i;
    for(i=1;i<=n;i++)
    {
        memset(v,0,sizeof(v));//每次都要把该数组初始化。
        if(dfs(1,i))
        {
            break;
        }
    }
    cout << i << endl;
    for(int j=1;j<=i;j++)
    {
        cout << v[j].l << " ";
        for(int k=1;k<=v[j].l;k++)
        {
            cout << v[j].a1[k] << " ";
        }
        cout << endl;
    }
    return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
基于微信小程序的家政服务预约系统采用PHP语言和微信小程序技术,数据库采用Mysql,运行软件为微信开发者工具。本系统实现了管理员和客户、员工三个角色的功能。管理员的功能为客户管理、员工管理、家政服务管理、服务预约管理、员工风采管理、客户需求管理、接单管理等。客户的功能为查看家政服务进行预约和发布自己的需求以及管理预约信息和接单信息等。员工可以查看预约信息和进行接单。本系统实现了网上预约家政服务的流程化管理,可以帮助工作人员的管理工作和帮助客户查询家政服务的相关信息,改变了客户找家政服务的方式,提高了预约家政服务的效率。 本系统是针对网上预约家政服务开发的工作管理系统,包括到所有的工作内容。可以使网上预约家政服务的工作合理化和流程化。本系统包括手机端设计和电脑端设计,有界面和数据库。本系统的使用角色分为管理员和客户、员工三个身份。管理员可以管理系统里的所有信息。员工可以发布服务信息和查询客户的需求进行接单。客户可以发布需求和预约家政服务以及管理预约信息、接单信息。 本功能可以实现家政服务信息的查询和删除,管理员添加家政服务信息功能填写正确的信息就可以实现家政服务信息的添加,点击家政服务信息管理功能可以看到基于微信小程序的家政服务预约系统里所有家政服务的信息,在添加家政服务信息的界面里需要填写标题信息,当信息填写不正确就会造成家政服务信息添加失败。员工风采信息可以使客户更好的了解员工。员工风采信息管理的流程为,管理员点击员工风采信息管理功能,查看员工风采信息,点击员工风采信息添加功能,输入员工风采信息然后点击提交按钮就可以完成员工风采信息的添加。客户需求信息关系着客户的家政服务预约,管理员可以查询和修改客户需求信息,还可以查看客户需求的添加时间。接单信息属于本系统里的核心数据,管理员可以对接单的信息进行查询。本功能设计的目的可以使家政服务进行及时的安排。管理员可以查询员工信息,可以进行修改删除。 客户可以查看自己的预约和修改自己的资料并发布需求以及管理接单信息等。 在首页里可以看到管理员添加和管理的信息,客户可以在首页里进行家政服务的预约和公司介绍信息的了解。 员工可以查询客户需求进行接单以及管理家政服务信息和留言信息、收藏信息等。
数字社区解决方案是一套综合性的系统,旨在通过新基建实现社区的数字化转型,打通智慧城市建设的"最后一公里"。该方案以国家政策为背景,响应了国务院、公安部和中央政法会议的号召,强调了社会治安防控体系的建设以及社区治理创新的重要性。 该方案的建设标准由中央综治办牵头,采用"9+X"模式,通过信息采集、案(事)件流转等手段,实现五级信息中心的互联互通,提升综治工作的可预见性、精确性和高效性。然而,当前社区面临信息化管理手段不足、安全隐患、人员动向难以掌握和数据资源融合难等问题。 为了解决这些问题,数字社区建设目标提出了"通-治-服"的治理理念,通过街道社区、区政府、公安部门和居民的共同努力,实现社区的平安、幸福和便捷。建设思路围绕"3+N"模式,即人工智能、物联网和数据资源,结合态势感知、业务分析和指挥调度,构建起一个全面的数据支持系统。 数字社区的治理体系通过"一张图"实现社区内各维度的综合态势可视化,"一套表"进行业务分析,"一张网"完成指挥调度。这些工具共同提升了社区治理的智能化和效率。同时,数字社区还提供了包括智慧通行、智慧环保、居家养老和便民服务等在内的多样化数字服务,旨在提升居民的生活质量。 在硬件方面,数字社区拥有IOT物联网边缘网关盒子和AI边缘分析盒子,这些设备能够快速集成老旧小区的物联设备,实现传统摄像设备的智能化改造。平台优势体现在数字化能力中台和多样化的应用,支持云、边、端的协同工作,实现模块化集成。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

\ 安 /

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值