codeforces B
来源:互联网 发布:linux新建配置conf文件 编辑:程序博客网 时间:2024/03/29 20:39
之前比赛以为是组合数,结果没写出来,然后手推规律,发现有个2的幂,但是不知道0的情况怎么解决,没想到打表。。
首先暴力打了个表:
#include <bits/stdc++.h>using namespace std;const int mod=1000000007;const int MAXN = 15;int n, m, k;int ans;int a[MAXN][MAXN];bool check(){ int x=1, y=1;// for(int i=1;i<=n;++i)// {// for(int j=1;j<=m;++j)// printf("%d%c", a[i][j],j==m?'\n':' ');// } for(int i=1;i<=n;++i) { x=1; for(int j=1;j<=m;++j) { x*=a[i][j]; } if(x!=k) return false; } for(int i=1;i<=m;++i) { y=1; for(int j=1;j<=n;++j) { y*=a[j][i]; } if(y!=k) return false; } return true;}void dfs(int x, int y){ if(x==n+1) { if(check()) ans++; return ; } a[x][y]=1; if(y+1>m) dfs(x+1,1); else dfs(x,y+1); a[x][y]=-1; if(y+1>m) dfs(x+1,1); else dfs(x,y+1); return ;}int main(){ while(~scanf("%d %d %d", &n, &m, &k)) { memset(a,0,sizeof(a)); ans=0; dfs(1,1); printf("%d\n", ans); } return 0;}
发现有一个2的幂的倍数,然后如果k=-1并且两个数互为奇偶,那么就是0
判断两个数互为奇偶 (a^b)&1
#include <bits/stdc++.h>using namespace std;const int MAXN = 1005;const int mod = 1e9+7;typedef long long LL;LL n, m, k;LL quick_pow(LL a, LL b){ LL ans=1; while(b) { if(b&1) ans=ans*a%mod; a=a*a%mod; b>>=1; } return ans%mod;}int main(){ scanf("%lld %lld %lld", &n, &m, &k); if(k==-1) if((n&1)!=(m&1)) { puts("0"); return 0; } printf("%lld\n", quick_pow(quick_pow(2,n-1),m-1)); return 0;}
阅读全文
0 0
- codeforces B
- codeforces B
- codeforces B
- codeforces B
- CodeForces 626B CodeForces 626B【暴力】
- CodeForces 841B (B) 博弈
- codeforces 134B
- codeforces#98 b
- codeforces 105 div2 B
- Codeforces 166B - Polygons
- codeforces B. Coins
- codeforces----193B Xor
- codeforces----208B Solitaire
- Codeforces 1B - Spreadsheet
- codeforces 214B Hometask
- Codeforces Round #136 B
- CodeForces 224B Array
- Problem - 216B - Codeforces
- Git入门
- easyui from 单选按钮radio,无法load到值
- c# 计算两日期的工作时间间隔(排除非工作日)及计算下一个工作时间点.
- Android必知必会-Android Studio下配置和使用Lambda
- 605. Can Place Flowers (数组)
- codeforces B
- 系统恢复
- HDU-1196(lowest bit)
- VO、DTO、DO、PO概念,区别与联系
- 为什么要使用数据源
- Spring常见面试题
- windows中安装Node.js-安装angular-cli
- HDU-2106(decimal system)
- 机器学习入门书籍导读-高等数学上