http://www.cppblog.com/menjitianya/archive/2011/04/06/143506.html关键是如何求最少的交换次数,用到了简单哈希#include<cstdio>#include<cstring>#include<algorithm>using namespace std;typedef long long lld;#define lowbit(x) (x&-x)const int maxn = 100010;int c[maxn],hash[maxn],val[maxn],a[maxn];void upda Read More
posted @ 2012-03-08 22:03 Because Of You Views(329) Comments(1) Diggs(0) Edit
http://www.lightoj.com/volume_showproblem.php?problem=1166从后往前贪心,把i位置上的数放到i位置上(对不起,我只知道AC)View Code #include<stdio.h>#include<iostream>using namespace std;int a[110];int main(){ int t,n,i,j,cases=1; scanf("%d",&t); for(cases=1;cases<=t;cases++) { int tot=0; scanf("% Read More
posted @ 2012-03-08 20:32 Because Of You Views(698) Comments(0) Diggs(0) Edit
DP过程注意:对于每个矛盾关系,从老板向员工连一条边dp[i][0]表示不取i的最大值,可以由两个状态转移而来dp[i][0]+=sigma[ max(dp[j][0],dp[j][1])],j为儿子,即儿子取或不取都可以dp[i][1]表示取i的最大值,初始值赋为1,那么儿子节点就不能取了,所以dp[i][1]=sigma(dp[j][0]);判断方案是否唯一观察状态转移的过程可知:dp[i][0]是由dp[j][0],dp[j][1]两个状态过来的,所以当dp[j][0]==dp[j][1]时,方案不唯一,即子节点选与不选都可以但是注意前提是dp[i][0]更优与dp[i][1],即i这个 Read More
posted @ 2012-03-08 19:22 Because Of You Views(1010) Comments(0) Diggs(0) Edit
先用两个dfs暴力求出所有的lucky numbers,然后二分lucky number数组的下标,求出答案View Code #include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<vector>using namespace std;typedef __int64 lld;vector<lld> lu,res;int tot;void dfs(lld num,int de){ if(de==12) return ; l Read More
posted @ 2012-03-08 16:47 Because Of You Views(437) Comments(0) Diggs(0) Edit