2018宁夏邀请赛 - Copy and Submit II(推公式)
生活随笔
收集整理的這篇文章主要介紹了
2018宁夏邀请赛 - Copy and Submit II(推公式)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題目鏈接:點擊查看
題目大意:給出一段程序,你可以選擇直接提交,也可以不直接提交
題目分析:挺好玩的一個題,內存只給了512K,如果直接提交原代碼,數組都開不出來,更別說遞歸了,這個題顯然不能用記憶化搜索(數組開不了),也不能用遞歸(n太大,時間不夠用),所以我們應該往遞推方面去思考,如果直接以k開始往下展開,會很抽象,我們可以以具體的實例來展開試試:
寫三個具體的實例再提取公因式化簡一下,公式就顯而易見了,直接模擬一下就成簡單水題了:
記得ans要開long long,因為相乘的時候1e9+7*1e4會爆掉int
#include<iostream> #include<string> #include<cstring> #include<cstdio> #include<algorithm> #include<climits> #include<cmath> #include<cctype> #include<stack> #include<queue> #include<list> #include<vector> #include<set> #include<map> #include<sstream> using namespace std;typedef long long LL;const int inf=0x3f3f3f3f;const int N=1e6+100;const int M=1e9+7;int main() { // freopen("input.txt","r",stdin);int n;while(scanf("%d",&n)!=EOF){LL ans=1;while(n--){int num;scanf("%d",&num);ans=ans*(num+1)%M;}printf("%lld\n",ans);}return 0; }?
總結
以上是生活随笔為你收集整理的2018宁夏邀请赛 - Copy and Submit II(推公式)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 高精度运算模板(大数模板)
- 下一篇: 扩展中国剩余定理(模板)