Codeforces Round #359 (Div. 2) C. Robbers' watch dfs
来源:互联网 发布:手机淘宝能实名认证吗 编辑:程序博客网 时间:2024/06/05 18:35
参考http://www.cnblogs.com/baocong/p/5913936.html
题意:给你n和m,找出(a,b)的对数,其中a满足要求:0<=a<n,a的7进制的位数和n-1的7进制的位数相同,b满足要求:0<=b<m,b的7进制的位数和m-1的7进制的位数相同,且a和b的7进制下的位上的数都不相同,即如果a的七进制数为10,b的7进制数为21,这种情况是不行的,因为重复了1题解:先计算n,m各需要多少位(注意7需要1位就够了,而不是两位),枚举每一位的数,一个标记数组就可以了,找完a再找b,注意中间的回溯,找完b检查一下就好了
╮(╯▽╰)╭。没有看出是dfs。。然后以为是数学的组合排列。。。
原来可以直接暴力。。
大佬的代码。能那么快调出来也是很强。。。
#include<bits/stdc++.h>using namespace std;#define LL long long#define MP(a,b) make_pair(a,b)#define mem(a,b) memset(a,b,sizeof(a))#define REP(i,a,b) for(int i=a;i<=b;++i)#define FOR(i,a,b) for(int i=a;i<b;++i)#define pii pair<int,int>#define sf scanf#define pf printfconst LL maxn = (LL)1e9;LL seven[15];bool vis[15];LL res1[4010], res2[4010];int sum = 0;void dfs(int poi, int type, LL now, int len, LL lim, LL *arr){ //pf("poi = %d, len = %d\n", poi, len); if(poi > len) { //++sum; ++arr[type]; return; } REP(i,0,6) if(!vis[i]) { //pf("adsf\n"); LL res = seven[poi]*i + now; if(res >= lim) continue; vis[i] = true; dfs(poi+1, type+(1<<i), res, len, lim, arr); vis[i] = false; } return;}int get_len(LL x){ int i = 1; while(seven[i+1] <= x) ++i; return i;}void init(){ LL n, m; cin >> n >> m; //n = maxn; m = maxn; seven[1] = 1; REP(i,2,13) seven[i] = seven[i-1] * 7; mem(vis, 0); mem(res1,0); mem(res2,0); int len1 = get_len(n-1); int len2 = get_len(m-1); //pf("len1 = %d, len2 = %d\n", len1, len2); dfs(1, 0, 0, len1, n, res1); dfs(1, 0, 0, len2, m, res2); /*REP(i,1,1024) { if(res1[i]) pf("res1[%d] = %lld\n", i, res1[i]); } REP(i,1,1024) { if(res2[i]) pf("res2[%d] = %lld\n", i, res2[i]); }*/ int up = 1<<8 - 1; //pf("up = %d\n", up); LL ans = 0; REP(i,1,up) REP(k,1,up) { if(i & k) continue; //if(res1[i] && res2[k]) // pf("i = %d, k = %d\n", i, k); ans += res1[i] * res2[k]; } cout << ans << "\n"; //cout << "sum = " << sum << endl;}int main(){ //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); init(); return 0;}
阅读全文
0 0
- Codeforces Round #359 (Div. 2) C. Robbers' watch (DFS)
- Codeforces Round #359 (Div. 2) C. Robbers' watch dfs
- Codeforces Round #359 (Div. 2) C. Robbers' watch
- Codeforces Round #359 (Div. 2)C. Robbers' watch
- Codeforces Round #359 (Div. 2) C. Robbers' watch
- Codeforces Round #359 (Div. 1) A. Robbers' watch 暴力
- CodeForces 686C Robbers' watch (dfs)
- Codeforces Round #359 (Div. 2) C DFS
- CodeForces 686C Robbers' watch
- Codeforces Round #301 C (Div. 2) 【dfs】
- Codeforces Round #321 (Div. 2) C DFS
- Codeforces Round #376 (Div. 2)C(DFS)
- CodeForces 685A 686C Robbers' watch
- codeforces_686C. Robbers' watch(dfs)
- Codeforces Round #359 (Div. 2) D DFS
- Classroom Watch (Codeforces Round #441 (Div.2) )
- Codeforces Round #256 (Div. 2) C. Painting Fence (DFS)
- Codeforces Round #321 (Div. 2)(C)模拟,DFS
- win10下让outlook2016开机自启动
- LeetCode 59. Spiral Matrix II
- 如何自学编程有哪些窍门
- [编程题]堆砖块
- 在linux操作系统下,进行j2ee的web开发,是怎么一个过程和体验?
- Codeforces Round #359 (Div. 2) C. Robbers' watch dfs
- Android---广播机制简介
- 总结
- HDU 2188 博弈 + sg打表
- 如何学习javascript
- haar 人脸检测算法 Viola Jones Face Detector
- 修改tomcat默认的编码方式
- linux如何卸载openjdk并安装配置sun JDK1.8
- XUtils3