摘要:
背包,输出方案数!#include#include#include#define maxn 505using namespace std;int f[maxn];int cot[maxn];int num[maxn];int main(){ int n,m,t; scanf("%d",&t); while(t--) { int mi=1=num[i]; j--) { if(f[j]==f[j-num[i]]+1) cot[j]+=cot[j-num[i]]; ... 阅读全文
摘要:
01背包,输出方案#include#include#include#define maxn 100009using namespace std;int f[maxn];int num[30];int g[30][maxn];int cot[30];int main(){ int n,v; int sum; while(scanf("%d",&sum)!=EOF) { scanf("%d",&n); memset(f,0,sizeof f); memset(g,0,sizeof g); for(int i=1;i=0... 阅读全文
摘要:
1537:水题,排序贪心#include#include#include#define maxn 1009using namespace std;int num[maxn];int tmp[maxn];int b[maxn];int main(){ int n; while(scanf("%d",&n)&&n) { for(int i=1;in-i;j--) ans+=tmp[j]; ret=max(ret,ans); } printf("%d\n",ret); } re... 阅读全文
摘要:
#include#includeusing namespace std;int k,n;void dfs(int a,int b,int c,int d){ if(kn)return ; dfs(a,b,x,y); --k; if(k==0){printf("%d/%d\n",x,y);k--;return;} dfs(x,y,c,d);}int main(){ int t; scanf("%d",&t); while(t--) { scanf("%d",&n); scanf("%d",&k 阅读全文
摘要:
splay 练手用;杭电的oj要手动开栈;#include#pragma comment(linker, "/STACK:102400000,102400000")#include#include#define inf 999999#define maxn 1500009#define lch(rt) son[rt][0]#define rch(rt) son[rt][1]using namespace std;int son[maxn][2],fa[maxn];int val[maxn],size[maxn],flg[maxn];int cnt,root;int num[ 阅读全文
摘要:
splay#include#include#include#include#define maxn 300009#define lch(rt) son[rt][0]#define rch(rt) son[rt][1]using namespace std;int son[maxn][2],fa[maxn],size[maxn],val[maxn],st[maxn];int root,cnt;int num[maxn],flg[maxn];int n,m;void push_up(int rt){ size[rt]=size[lch(rt)]+size[rch(rt)]+1;}void p... 阅读全文
摘要:
简单dp#include#define maxn 10005#include#includeusing namespace std;double dp[140][maxn];double t[140][140];int num[maxn];int main(){ int n,m; while(scanf("%d",&m)!=EOF) { m=(m*(m-1)*(m-2)/6); for(int i=0; ima2)ma2=dp[i][j]; } ma1=ma2; } ma1=0... 阅读全文
摘要:
斜率dp#include#include#include#include#define maxn 10005#define maxm 5005using namespace std;int dp[maxn][maxm];int q[maxn*10];int num[maxn];bool check(int j,int tail,int i){ int yk=dp[q[tail-1]][j-1]+num[q[tail-1]+1]*num[q[tail-1]+1]; int yj=dp[q[tail]][j-1]+num[q[tail]+1]*num[q[tail]+1]; in... 阅读全文
摘要:
Good Serial Inc.比较简单;#include#include#include#define maxn 1000009#define ll long longusing namespace std;const ll mod=987654321;ll f[maxn]; int main(){ ll n,m; f[1]=1; for(ll i=2;imod)f[i]%=mod; } while(scanf("%lld%lld",&n,&m)&&(n+m)>0) { ll ans=1; if(n0) {... 阅读全文
摘要:
两种构造的方式都是正确的;1.#include#include#include#define maxn 60#define ll long longusing namespace std;int x;ll M,n;struct matrix{ int len_x; int len_y; ll data[maxn][maxn]; void ini() { len_x=0; len_y=0; memset(data,0,sizeof data); }};matrix mat_big;ll f[maxn][maxn];ma... 阅读全文