抗疫联合训练赛26 2020 02 25

问题 E: All-you-can-eat
Takahashi is at an all-you-can-eat restaurant.
The restaurant offers N kinds of dishes. It takes Ai minutes to eat the i-th dish, whose deliciousness is Bi.
The restaurant has the following rules:
·You can only order one dish at a time. The dish ordered will be immediately served and ready to eat.
·You cannot order the same kind of dish more than once.
·Until you finish eating the dish already served, you cannot order a new dish.
·After T−0.5 minutes from the first order, you can no longer place a new order, but you can continue eating the dish already served.
Let Takahashi’s happiness be the sum of the deliciousness of the dishes he eats in this restaurant.
What is the maximum possible happiness achieved by making optimal choices?

Constraints
·2≤N≤3000
·1≤T≤3000
·1≤Ai≤3000
·1≤Bi≤3000
·All values in input are integers.

输入
Input is given from Standard Input in the following format:

N T
A1 B1
:
AN BN
输出
Print the maximum possible happiness Takahashi can achieve.
思路:

1
双向dp
dp1[i][j]表示在前i道菜中,有j时间所获得的最大值。
dp2[i][j]就是从后面开始的意思。 
2
改变上届
V-->V+w[i];	w[i]要从小到大排序。
然后ans=min(ans,dp[n][V+w[i] ]);
没有1好理解,这个要很好地理解状态转移的过程

问题 F: Laminate
时间限制: 1 Sec 内存限制: 128 MB
[提交] [状态]
题目描述
We will create an artwork by painting black some squares in a white square grid with 109 rows and
N columns.
The current plan is as follows: for the i-th column from the left, we will paint the Hi bottommost squares and will not paint the other squares in that column.
Before starting to work, you can choose at most K columns (possibly zero) and change the values of
Hi for these columns to any integers of your choice between 0 and 109 (inclusive).
Different values can be chosen for different columns.
Then, you will create the modified artwork by repeating the following operation:
Choose one or more consecutive squares in one row and paint them black. (Squares already painted black can be painted again, but squares not to be painted according to the modified plan should not be painted.)
Find the minimum number of times you need to perform this operation.

Constraints
·1≤N≤300
·0≤K≤N
·0≤Hi≤109
·All values in input are integers.

输入
Input is given from Standard Input in the following format:

N K
H1 H2 … HN

输出
Print the minimum number of operations required.
思路 :

	k次操作相当于删掉k个值等效保留(n-k)个值
	dp[i][j]表示第i个是最后一个时保留j个的值
	n^3跑就行。

问题 G: Bitaro the Brave

时间限制: 1 Sec  内存限制: 256 MB
[提交] [状态]
题目描述
Bitaro the Brave faces the Devil.
Bitaro is going to attack the Devil by arranging jewels, orbs and ingots on an H times W grid and casting a spell. The square at the i-th row (1 ≤ i ≤ H) from the top and the j-th column (1 ≤ j ≤ W) from the left is denoted by (i, j).
Now, Bitaro has arranged one of these three types on each square. Bitaro is going to cast a spell, the power of which is determined by the arrangement of jewels, orbs and ingots. Specifically, the power equals to the number of quadruplets of integers (i, j, k, L) (1 ≤ i < k ≤ H, 1 ≤ j < L ≤ W) satisfying the following condition.
Condition: Bitaro has arranged a jewel on the square (i, j), an orb on the square (i, L) and an ingot on the square (k, j).
Bitaro is wondering the power of the spell.
Write a program which, given the arrangement of jewels, orbs and ingots, calculates the power of the spell Bitaro casts.


输入
Read the following data from the standard input.
H W
S1
:
SH
Si (1 ≤ i ≤ H) is a string of length W. The item arranged on the square (i, j) (1 ≤ j ≤ W) is a jewel if the j-th character of Si is J, an orb if it is O and an ingot if it is I.
输出
Write one line to the standard output. The output should contain the power of the spell Bitaro casts.
样例输入 Copy
【样例1】
3 4
JOIJ
JIOO
IIII
【样例2】
4 4
JJOO
JJOO
IIJO
IIIJ
样例输出	Copy
【样例1】
3
【样例2】
17

思路

对于每一个J 的坐标 x,y ,s+=x下面的i的数量*y右面的o的数量
前后缀和思想就可以。

问题 O: 友好数对

时间限制: 1 Sec  内存限制: 128 MB
[提交] [状态]
题目描述
小X是⼀个有天生数感的好孩⼦,他总能从⼀些看似无关的数中找出友好关系。
小X认为两个数x和y有友好关系,当且仅当x xor y在⼆进制表示下恰有两位是1。这⾥xor是指按位异或。现在小X给你两组数{a1,a2,...,an}和{b1,b2,...,bm},问你有多少对(i,j),满足
1≤i≤n,1≤j≤m,ai和bj有友好关系。
输入
第⼀行为两个正整数n,m。 接下来⼀行n个非负整数,表示a1~an。 接下来⼀行m个非负整数,表示b1~bm。(n,m≤6≤100000,0≤6≤ai,bi<230。)
输出
输出一行一个整数,表示友好数对的个数。
样例输入 Copy
3 5
1 8 13
7 5 4 8 3
样例输出	Copy
7

思路:

x^y恰好有两位1 《==》x^(1<

问题 Q: 线性规划问题

时间限制: 1 Sec  内存限制: 128 MB
[提交] [状态]
题目描述
小Z在ACM比赛中遇到了一个线性规划问题,经过漫长的思索,始终难以窥见真谛。
这个问题是这样的:有三个长度为n的数列{a1,a2,...,an},{b1,b2,...,bn},{c1,c2,...cn},要满足约束

最小化

比赛还剩半小时就要结束,小Z所在的队能否A掉这题并取得金牌,就靠你了。
输入
一个测试点内含有T组测试数据,第一行为一个正整数T。
对于每组测试数据:
第一行两个正整数n,P。
第二行为n个非负整数,第i个数为ai。
第三行为n个非负整数,第i个数为bi。
第四行为n个非负整数,第i个数为ci。T≤5,ai≤bi,ci≤2×106,n≤1000
输出
对于每组测试数据:如果题目中的约束能被满足,你需要输出⼀个非负整数,代表w的最小值;否则你需要输出IMPOSSIBLE!!!。
样例输入 Copy
5
5 26
3 3 2 10 1 
7 10 13 16 3 
5 10 4 6 2 
5 25
1 3 6 10 13 
13 7 8 15 16 
2 3 10 2 7 
5 1
2 9 7 2 4 
4 10 7 6 7 
0 0 0 0 0 
5 7
2 6 1 9 11 
7 11 12 16 16 
1 7 8 4 5 
5 24
9 1 13 7 4 
13 14 14 13 6 
7 6 5 8 2 

思路:

找到状态转移,对于每一个新到来的a[i],b[i],c[i];
去尝试他能否对前面的结果进行优化。
具体理解放代码。
#include
using namespace std;
#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1<<21, stdin), p1 == p2) ? EOF : *p1++)
#define swap(x,y) x ^= y, y ^= x, x ^= y
typedef long long ll;
const int MAXN = 3 * 1e6 + 10, P = 998244353, G = 3, Gi = 332748118;
char buf[1<<21], *p1 = buf, *p2 = buf;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
const int N=1e3+15;
int n,m,a[N],b[N],c[N],q[100*N],f[2][100*N];
void solve()
{
    int x=0,y=0,l=1,r=0;
    //f[0][m]=f[1][m]=2e9+1;
    for(int i=1;i<=n;i++)
    {
        y=x;x=y^1,l=1,r=0;
        for(int j=0;j<=m;j++)
        {
            f[x][j]=f[y][j];
            ///更新l
            while(l<=r&&j-q[l]>b[i])    ///q[l]+b[i] >= j 时跳出
            {
                l++;
            }
            ///如果l符合条件 试试是否可以更新f[x][j]; 存在q[l]+b[i] >= j    而且j-q[l]==a[i] 且 q[l]+a[i]==j
            if(l<=r)
                f[x][j]=min(f[x][j],f[y][q[l]]+c[i]);
            if(j+1-a[i]>=0)       /// j-a[i]<=m)
            {
                while(l<=r&&f[y][q[r]]>=f[y][j-a[i]+1] )
                    r--;
                q[++r]=j-a[i]+1;
            }
            ///更新q;
            ///r--
        }
        ///更新l,r
    }
    if(min(f[y][m],f[x][m])<=2e9)
    {
        cout<<f[x][m]<<endl;
    }
    else
        cout<<"IMPOSSIBLE!!!"<<endl;
    return ;
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        cin>>n>>m;
        for(int i=1;i<=n;i++)
            cin>>a[i];
        for(int i=1;i<=n;i++)
            cin>>b[i];
        for(int i=1;i<=n;i++)
            cin>>c[i];
        for(int i=1;i<=m;i++)
            f[0][i]=2e9+1;
        f[0][0]=0;
        solve();
    }
    return 0;
}
 

你可能感兴趣的:(抗疫联合训练赛)