acm
題意:
中文題意,不解釋。
分析:100w的資料,暴力打錶能過
先初始化dp陣列,表示前i位的三種情況,再進行推算
直接dfs,一遍搜一變記錄,可能有不飢渴的全部算和飢渴的部分算情況,記錄只能記錄全部算(推薦看∑大的詳細題解orz)
**:
1. 暴力 (以前寫的)
/*
* author: illuz * file: 2089_bf.cpp
* create date: 2014-03-31 20:28:46
* descripton: brute force way
*/#include #define rii(x,y) scanf("%d%d",&x,&y)
#define pin(x) printf("%d\n",x)
#define repf(i,a,b) for(int i=(a);i<=(b);i++)
const int n = 1000010;
int f[n], n, m;
bool check(int r)
return true;
}void init()
int main()
return 0;
}
2. dp_1
/*
* author: illuz * file: 2089.cpp
* create date: 2014-07-26 09:55:48
* descripton:
*/#include #include #include #include using namespace std;
#define rii(x,y) scanf("%d%d",&x,&y)
#define pin(x) printf("%d\n",x)
#define repf(i,a,b) for(int i=(a);i<=(b);i++)
#define repd(i,a,b) for(int i=(a);i>=(b);i--)
const int n = 10;
int n, m;
int bits[n];
int dp[n][3]; // [len][x]
// 0->luck
// 1->luck and highest is 2
// 2->unluck
void init()
}int solve(int num)
bits[len + 1] = 0;
ans = 0; // the unluck num
repd (i, len, 1) else
if (bits[i] > 6)
if (bits[i + 1] == 6 && bits[i] > 2)
} if (bits[i] == 4 || (bits[i + 1] == 6 && bits[i] == 2))
} return rec - ans;
}int main()
return 0;
}
3. dp_2(dfs)
/*
* author: illuz * file: 2089_dfs.cpp
* create date: 2014-07-26 15:21:12
* descripton: dfs version
*/#include #include #include #include using namespace std;
#define rii(x,y) scanf("%d%d",&x,&y)
#define pin(x) printf("%d\n",x)
const int n = 10;
int bits[n], dp[n][2]; // dp[i][is6] is the number of i-len digits with (if prevent number is 6), its digits are from 0-9
// the rest length, is the prevent digit 6, is the digit max
int dfs(int len, bool is6, bool ismax)
return ismax ? cnt : dp[len][is6] = cnt; // remember the result
}int solve(int num)
return dfs(len, false, true);
}int main()
return 0;
}
HDU2089 不要62 數字DP
problem description 杭州人稱那些傻乎乎粘嗒嗒的人為62 音 laoer 杭州交通管理局經常會擴充一些的士車牌照,新近出來乙個好訊息,以後上牌照,不再含有不吉利的數字了,這樣一來,就可以消除個別的士司機和乘客的心理障礙,更安全地服務大眾。不吉利的數字為所有含有4或62的號碼。例如 ...
Hdu2089 不要62 數字dp
include includeint dp 10 3 dp i 0 為位數小於等於i且不含62也不含4的數字的個數 dp i 1 為位數為i且首位為2且不含62也不含4的數字的個數 dp i 2 為位數小於等於i且含62或4的數字的個數 int digit 10 void er int wei in...
hdu 2089 不要62 (數字dp)
思路 用變數記錄吉利數,和最高位為2的吉利數還有不是吉利數的個數。code include include includeusing namespace std int dp 10 3 dp i j i表示位數,j表示狀態 dp i 0 表示不存在不吉利數字 dp i 1 表示不存在不吉利數字,且最...