每个ai在最后sum中的值是本身值乘上组合数,按这个dfs一下即可 #include<iostream> #include<cstdio> using namespace std; int n,s,ans[15],c[20][20]; bool u[15],f=0; int dfs(int a,int b) { if(b==n) { if(a==s) f=1; return 0; } for(int i=1;i<=n;i++) if(!u[i]) { u[i]=1,ans[b…
[题目分析] 劳逸结合好了. 杨辉三角+暴搜. [代码] #include <cstdio> #include <cstring> #include <cmath> #include <cstdlib> #include <map> #include <set> #include <queue> #include <string> #include <iostream> #include <a…
1653: [Usaco2006 Feb]Backward Digit Sums Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 285  Solved: 215[Submit][Status] Description FJ and his cows enjoy playing a mental game. They write down the numbers from 1 to N (1 <= N <= 10) in a certain orde…
http://www.lydsy.com/JudgeOnline/problem.php?id=1653 看了题解才会的..T_T 我们直接枚举每一种情况(这里用next_permutation,全排列) 然后判断是否符合情况(累加判断) #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream> #include <…
1653: [Usaco2006 Feb]Backward Digit Sums Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 207  Solved: 161[Submit][Status][Discuss] Description FJ and his cows enjoy playing a mental game. They write down the numbers from 1 to N (1 <= N <= 10) in a cer…
Backward Digit Sums Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4487   Accepted: 2575 Description FJ and his cows enjoy playing a mental game. They write down the numbers from 1 to N (1 <= N <= 10) in a certain order and then sum ad…
参考:https://blog.csdn.net/mars_ch/article/details/53011234 我背包真是好不熟练啊-- 第一天买了第三天卖相当于第一天买了第二天卖第二天再买第三天再卖.所以问题转化成完全背包,每天转移即可 #include<iostream> #include<cstdio> #include<algorithm> #include<cstring> using namespace std; const int N=55…
严格次短路模板,用两个数组分别维护最短路和次短路,用dijskstra,每次更新的时候先更新最短路再更新次短路 写了spfa版的不知道为啥不对-- #include<iostream> #include<cstdio> #include<queue> using namespace std; const int N=5005,inf=1e9; int n,m,h[N],cnt,d1[N],d2[N]; struct qwe { int ne,to,va; }e[2000…
t记录每个格子最早被砸的时间,bfs(x,y,t)表示当前状态为(x,y)格子,时间为t.因为bfs,所以先搜到的t一定小于后搜到的,所以一个格子搜一次就行 #include<iostream> #include<cstdio> #include<queue> using namespace std; const int N=505,inf=1e9,dx[]={-1,1,0,0,0},dy[]={0,0,-1,1,0}; int n,m,t[N][N]; bool v[…
DAG上的dp 因为本身升序就是拓扑序,所以建出图来直接从1到ndp即可,设f[i][j]为到i花费了j #include<iostream> #include<cstdio> using namespace std; const int N=1005,inf=1e9+7; int n,m,b,h[N],cnt,f[N][N],ans=-inf; struct qwe { int ne,to,va,c; }e[N*10]; int read() { int r=0,f=1; cha…