传送门 背包经典题. 直接f[i][j]f[i][j]f[i][j]表示选i张牌和为j的方案数. 最后统计答案就行了. 代码: #include<bits/stdc++.h> #define N 55 #define ll long long using namespace std; ll f[N][N*N],ans=0; int x,a,n; int main(){ f[0][0]=1,scanf("%d%d",&n,&a); for(int i=1;i&…
传送门 昨晚打比赛的时候不是很机智啊. 这道题贪心就能过了. 我们可以发现一个明显的结论,每次选的垃圾的距离从大到小排序之后,每个距离对答案的贡献的系数是5,5,7,9,11-也就是最远的是5,其余都是2*rank+1. 这样就可以根据每次选几个垃圾来贪心. 代码: #include<bits/stdc++.h> #define ll long long #define N 200005 using namespace std; inline int read(){ int ans=0; ch…
传送门 一道挺有意思的贪心. 从1到n依次满足条件. 注意要特判第一个数已经大于x的情况. 但是如何贪心吃呢? 如果靠左的数没有越界,我们吃靠右的数. 原因是下一次靠右的数就会成为靠左的数,相当于多贡献了一次. 然后貌似要开long long 代码: #include<bits/stdc++.h> #define N 100005 #define ll long long using namespace std; ll a[N],x,ans=0; int n; inline ll read()…
传送门 有个十分显然的结论,只用枚举前后两个面就可以知道所有的面的颜色. 于是可以O(n2)O(n^2)O(n2)枚举前后两个面然后用map乱搞求贡献. 发现这样算出来会多算两倍(打表证明)于是答案除以3. 代码: #include<bits/stdc++.h> #define ll long long #define N 405 using namespace std; inline int read(){ int ans=0; char ch=getchar(); while(!isdig…
传送门 就是一个另类最短路啊. 利用颜色判断当前节点的最小花费的前驱边中有没有跟当前的边颜色相同的. 如果有这条边费用为0,否则费用为1. 这样跑出来就能ac了. 代码: #include<bits/stdc++.h> #define N 500005 #define M 500005 using namespace std; inline int read(){ int ans=0; char ch=getchar(); while(!isdigit(ch))ch=getchar(); wh…
215 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26. What is the sum of the digits of the number 21000? 题目大意: 题目大意: 215 = 32768 并且其各位之和为 is 3 + 2 + 7 + 6 + 8 = 26. 21000 的各位数之和是多少? // (Problem 16)Power digit sum // Completed on Sun, 17 No…